我正在尝试将依赖项注入我的 Ember 模型中。
https://github.com/emberjs/ember.js/issues/3670,表明此功能已禁用。通过链接访问https://github.com/stefanpenner/ember-cli/blob/master/blueprint/app/app.js#L4演示如何启用MODEL_FACTORY_INJECTIONS
,从理论上讲,这应该允许我将依赖项注入到我的模型中,但是我没有运气。
在没有此解决方案的情况下,除了将其转储到应用程序的命名空间(即 App.ImAGlobalconfig`)之外,是否还有其他方法将对应用程序范围的全局单例对象的引用注入到 Ember.Model 中?
作为参考,这是我正在研究的初始化程序
App.initializer({
name: 'preload',
initialize: function(container/*, application*/) {
App.deferReadiness();
Ember.$.ajax({
url: CONFIG.configURL,
dataType: 'json',
context: this
}).done(
function(json/*,status, request*/) {
var appConfig;
// ...
container.register('app:config', appConfig, {instantiate: false});
container.injection('controller', 'appConfig', 'app:config');
container.injection('route', 'appConfig', 'app:config');
container.injection('view', 'appConfig', 'app:config');
container.injection('model', 'appConfig', 'app:config'); // I don't work!
App.advanceReadiness();
}
).fail(
function(status, request, error) {
console.log('Unable to load config with: ' + error);
}
);
}
});
感谢您的任何和所有帮助/意见。