Ember。将附加服务注入附加 'areas'
Ember. Inject an addon service into additional 'areas'
我如何将插件服务注入其他 'places'?
例如,如果我安装一个插件,该插件使用以下代码注入控制器和组件:
export default {
name: 'notification-messages-service',
initialize() {
let application = arguments[1] || arguments[0];
application.register('notification-messages:service', NotificationMessagesService);
['controller', 'component'].forEach(injectionTarget => {
application.inject(injectionTarget, 'notifications', 'notification-messages:service');
});
}};
然后我如何将相同的服务(相同的单例)注入 services & routes - 我的要求实际上是注入单个服务,服务:消息?
我不相信我可以使用
notifications: Ember.inject.service();
因为插件中服务是这样写的:
export default Ember.ArrayProxy.extend({...});
我当然可以更改插件,但是一旦插件更新,我的更改就会消失。
感谢观看,N
notifications: Ember.inject.service('notification-messages');
应该可以
如果服务名称与 属性 名称相同,service
的参数是可选的,但最好始终使用它
P.S. 正常服务上面的代码
在你的情况下代码
['controller', 'component'].forEach(injectionTarget => {
application.inject(injectionTarget, 'notifications', 'notification-messages:service');
});
表示controllers/components刚刚得到新的属性notifications
所以在你的 controllers/components 里面你可以使用
this.get('notifications')
通过使用以下代码创建一个新的初始化程序,我能够将插件注入到我的特定服务中:
export default {
name: 'inject-ember-notification-service',
initialize: function(container, app) {
app.inject('services:message', 'notifications', 'notification-messages:service');
}
};
极其迟钝,ember!
感谢大家的参与。
我如何将插件服务注入其他 'places'?
例如,如果我安装一个插件,该插件使用以下代码注入控制器和组件:
export default {
name: 'notification-messages-service',
initialize() {
let application = arguments[1] || arguments[0];
application.register('notification-messages:service', NotificationMessagesService);
['controller', 'component'].forEach(injectionTarget => {
application.inject(injectionTarget, 'notifications', 'notification-messages:service');
});
}};
然后我如何将相同的服务(相同的单例)注入 services & routes - 我的要求实际上是注入单个服务,服务:消息?
我不相信我可以使用
notifications: Ember.inject.service();
因为插件中服务是这样写的:
export default Ember.ArrayProxy.extend({...});
我当然可以更改插件,但是一旦插件更新,我的更改就会消失。
感谢观看,N
notifications: Ember.inject.service('notification-messages');
应该可以
如果服务名称与 属性 名称相同,service
的参数是可选的,但最好始终使用它
P.S. 正常服务上面的代码 在你的情况下代码
['controller', 'component'].forEach(injectionTarget => {
application.inject(injectionTarget, 'notifications', 'notification-messages:service');
});
表示controllers/components刚刚得到新的属性notifications
所以在你的 controllers/components 里面你可以使用
this.get('notifications')
通过使用以下代码创建一个新的初始化程序,我能够将插件注入到我的特定服务中:
export default {
name: 'inject-ember-notification-service',
initialize: function(container, app) {
app.inject('services:message', 'notifications', 'notification-messages:service');
}
};
极其迟钝,ember!
感谢大家的参与。