简体   繁体   English

为什么Ember.js / EAK会自动生成ApplicationController而不是使用我的显式ApplicationController?

[英]Why does Ember.js / EAK autogenerate ApplicationController instead of using my explicit ApplicationController?

I'm using Ember App Kit (EAK). 我正在使用Ember App Kit(EAK)。

The Ember Inspector / Chrome Dev Tools console shows this line when I load my index page: 加载索引页时,Ember Inspector / Chrome Dev Tools控制台会显示以下行:

*generated -> controller:application Object {fullName: "controller:application"}*

But I've explicitly created an Application Controller, which this Ember app apparently doesn't know about (since it's autogenerating an ApplicationController). 但我明确地创建了一个应用程序控制器,这个Ember应用程序显然不知道(因为它自动生成ApplicationController)。

I'm trying to call a title property on my explicit Application Controller, and display it in my application template. 我正在尝试在我的显式应用程序控制器上调用title属性,并将其显示在我的应用程序模板中。

What am I doing wrong? 我究竟做错了什么? The {{title}} in the template yields nothing. 模板中的{{title}}不会产生任何结果。

(I suspect it has to do with the way EAK uses ECMAScript 6 modules via the ES6 Module Transpiler.) (我怀疑它与EAK通过ES6 Module Transpiler使用ECMAScript 6模块的方式有关。)


/site/app/templates/application.hbs /site/app/templates/application.hbs

{{title}}

{{outlet}}

/site/app/controllers/application.js /site/app/controllers/application.js

var ApplicationController = Ember.Controller.extend({
    title: 'hello world'
});

export default ApplicationController;

有时可以帮助重启你的grunt服务器。

Your code seems ok to me. 你的代码对我来说似乎没问题。 Which Ember.js and app-kit versions do you use? 您使用哪种Ember.js和app-kit版本?

I tried to replicate your issue but everything worked well. 我试图复制你的问题,但一切都运作良好。 Can you please replicate my scenario and verify that it also works for you? 你能复制一下我的场景并确认它对你有用吗?

What I did: 我做了什么:

$ git clone git@github.com:stefanpenner/ember-app-kit.git
$ cd ember-app-kit
$ npm install

Made these code changes (my git diff): 做了这些代码更改(我的git差异):

diff --git a/app/controllers/application.js b/app/controllers/application.js
new file mode 100644
index 0000000..9d34ee0
--- /dev/null
+++ b/app/controllers/application.js
@@ -0,0 +1,5 @@
+var ApplicationController = Em.Controller.extend({
+    title: 'hello world'
+});
+
+export default ApplicationController;
diff --git a/app/templates/application.hbs b/app/templates/application.hbs
index d08c11f..a373a71 100644
--- a/app/templates/application.hbs
+++ b/app/templates/application.hbs
@@ -1,3 +1,4 @@
 <h2 id='title'>Welcome to Ember.js</h2>
+{{title}}

 {{outlet}}

and finally ran 然后跑了

$ grunt server

and when I opened localhost:8000 everything worked fine ("hello world" was rendered). 当我打开localhost:8000时,一切正常(“hello world”已呈现)。 Can you please try it out? 你能试一试吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM