Ember.js:htmlbar和handlebar.compile命令

Ember.js:htmlbar和handlebar.compile命令,ember.js,ember-cli,Ember.js,Ember Cli,运行我的应用程序时出现以下错误: Uncaught Error: Cannot call `compile` without the template compiler loaded. Please load `ember-template-compiler.js` prior to calling `compile`. 它与这段代码有关: var CarouselView = Ember.View.extend({ template: Ember.Handlebars.compile

运行我的应用程序时出现以下错误:

Uncaught Error: Cannot call `compile` without the template compiler loaded. Please load `ember-template-compiler.js` prior to calling `compile`.
它与这段代码有关:

var CarouselView = Ember.View.extend({
    template: Ember.Handlebars.compile('{{view view.itemsView}}'),
    elementId: 'carousel',
    contentBinding: 'content',
    ...
在ember.js github上已经存在与此问题相关的问题:

然而,我在我的package.json中添加了
ember模板编译器
,再次出现相同的错误

我做到了:
npm安装--保存开发成员模板编译器

以下是我的package.json devdependency:

 "ember-cli": "0.1.10",
 "ember-cli-app-version": "0.3.0",
 "ember-cli-content-security-policy": "0.3.0",
 "ember-cli-dependency-checker": "0.0.7",
 "ember-cli-htmlbars": "^0.6.0",
 "ember-cli-ic-ajax": "0.1.1",
 "ember-cli-inject-live-reload": "^1.3.0",
 "ember-cli-qunit": "0.3.0",
 "ember-cli-simple-auth": "^0.7.2",
 "ember-cli-simple-auth-cookie-store": "^0.7.2",
 "ember-cli-simple-auth-oauth2": "^0.7.2",
 "ember-cli-uglify": "1.0.1",
 "ember-data": "1.0.0-beta.12",
 "ember-export-application-global": "^1.0.0",
 "ember-template-compiler": "^1.8.0",
 "express": "^4.8.5",
 "glob": "^4.0.5"
参考:余烬模板编译器


任何人都有使用HTMLBAR和compile命令的经验吗?

您正在尝试在客户端编译HTMLBAR模板,但是在
包中添加
ember模板编译器
。json
仅允许服务器端预编译HTMLBAR模板

要启用客户端编译,您应该将
ember模板编译器
添加到
bower.json
,例如(使用适当的版本)

然后将其包含在
Brocfile.js

app.import('bower_components/ember-template-compiler/index.js');

由于Ember.js 1.10模板编译器是Ember的一部分,所以在客户端编译模板所需做的就是在文件中添加以下行:

app.import('bower_components/ember/ember-template-compiler.js');

对于我的视图,我只是为它们创建了模板文件。以您的案例为例,我将创建app/templates/views/carousel.hbs:

{{view view.itemsView}}
然后旋转视图变成:

var CarouselView = Ember.View.extend({
  templateName: 'views/carousel',
  elementId: 'carousel',
  contentBinding: 'content',
  ...

这样,您就不必为客户机提供模板编译器。这将为客户端下载带来更好的性能和更小的负载。

这就成功了!然而,为什么这从未在互联网上记录?我创建了一个关于此问题最终文档的Github问题。您能添加到该问题的链接吗?背景信息:嗨,尽管遵循上述说明,我仍然在关注这一问题。链接到我的问题->嘿,你正在使用哪个brocfilte.plz Help在哪里添加这些行当我在Ember 2.0中找到Brocfile时,我得到了3个文件/home/nesh/paint/node_modules/Ember cli content security policy/Brocfile.js,其中一个是/home/nesh/paint/node_modules/Ember cli babel/Brocfile.jsi尝试在这2个文件中添加行,但我得到了相同的结果问题
var CarouselView = Ember.View.extend({
  templateName: 'views/carousel',
  elementId: 'carousel',
  contentBinding: 'content',
  ...