首先,我制作了一个没有 Ember CLI 的小型 Ember 应用程序。
我有这段代码。
window.MyApp = Ember.Application.create({
ready: function() {
this.register('session:current', MyApp.SessionController, { singleton: true });
this.inject('controller', 'session', 'session:current');
}
});
这奏效了。
然后我决定用 Ember CLI 从头开始重写一切。
我编辑了文件app/app.js
并添加了ready
就像我之前的版本一样。
var App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver: Resolver,
ready: function() {
this.register('session:current', App.SessionController, { singleton: true });
this.inject('controller', 'session', 'session:current');
}
});
这是行不通的。
会话控制器确实存在。这就是文件的内容app/controllers/session.js
export default Ember.Controller.extend({
isLoggedIn: false,
});
我收到的错误消息是
TypeError: Attempting to register an unknown factory: `session:current`
它出现在浏览器中。
我用 google 搜索了该消息,但在 Ember CLI 中没有找到任何有关依赖注入的信息。
任何想法?