[英]Ember.js: HtmlBars and the Handlebars.compile command
運行我的應用程序時出現以下錯誤:
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上已經存在與此問題相關的問題: https : //github.com/emberjs/ember.js/issues/10265
但是我在我的package.json中添加了ember-template-compiler
並再次遇到了同樣的錯誤。
我做了: npm install --save-dev ember-template-compiler
這是我的package.json devDependencies:
"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"
參考: ember-template-compiler
github頁面
有沒有HtmlBars和編譯命令的經驗?
由於Ember.js 1.10模板編譯器是Ember的一部分,因此在客戶端編譯模板所需要做的就是在Brocfile中添加以下行:
app.import('bower_components/ember/ember-template-compiler.js');
您正在嘗試在客戶端上編譯HTMLBars模板,但是在package.json
添加ember-template-compiler
只能啟用HTMLBars模板服務器端的預編譯。
要啟用客戶端編譯,您應該將ember-template-compiler
添加到bower.json
,例如(使用適當的版本)
"ember-template-compiler": "http://builds.emberjs.com/tags/v1.10.0-beta.3/ember-template-compiler.js"
然后將其包含在Brocfile.js
,
app.import('bower_components/ember-template-compiler/index.js');
對於我的觀點,我只是為它們創建了模板文件。 以您的案例為例,我將創建app / templates / views / carousel.hbs:
{{view view.itemsView}}
然后CarouselView變為:
var CarouselView = Ember.View.extend({
templateName: 'views/carousel',
elementId: 'carousel',
contentBinding: 'content',
...
這樣您就不必為客戶端提供模板編譯器。 應該為客戶端下載帶來更好的性能和更小的負載。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.