Ember.js:HtmlBars 和 Handlebars.compile 命令 [英] Ember.js: HtmlBars and the Handlebars.compile command

查看:14
本文介绍了Ember.js:HtmlBars 和 Handlebars.compile 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I get the following error when running my app:

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

There is already an issue related about this problem on ember.js github: https://github.com/emberjs/ember.js/issues/10265

但是我将 ember-template-compiler 添加到我的 package.json 并再次出现相同的错误.

However I added ember-template-compiler to my package.json and got the same error again.

我做到了:npm install --save-dev ember-template-compiler

这是我的 package.json devDependencies:

Here are my 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 和编译命令有经验吗?

Anyone has experience with HtmlBars and the compile command?

推荐答案

您正在尝试在客户端编译 HTMLBars 模板,但是在 package.json<中添加了 ember-template-compiler/code> 仅启用服务器端 HTMLBars 模板的预编译.

You are trying to compile HTMLBars template on the client, however adding ember-template-compiler in package.json only enables precompilation of HTMLBars templates server-side.

要启用客户端编译,您应该将 ember-template-compiler 添加到 bower.json,例如(使用合适的版本)

To enable client-side compilation, you should add ember-template-compiler to the bower.json, e.g. (use appropriate version)

"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');

这篇关于Ember.js:HtmlBars 和 Handlebars.compile 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆