從模板調用服務功能時,例如, onClick={{action myFirstLevel.hello}}
,應注入的服務myFirstLevel
停留undefined
。EmberJS從模板進行呼叫時不會注入第二級服務
通過組件動作的調用正在工作。
<button onClick={{action myFirstLevel.hello}}>Hello Service</button>
<button onClick={{action 'hello'}}>Hello Action</button>
App = Ember.Application.create();
App.MyFirstLevelService = Ember.Service.extend({
mySecondLevel: Ember.inject.service(),
hello: function() {
console.log('Hello first level');
this.get('mySecondLevel').hello();
}
});
App.MySecondLevelService = Ember.Service.extend({
hello: function() {
console.log('Hello second level');
}
});
App.MyButtonComponent = Ember.Component.extend({
myFirstLevel: Ember.inject.service(),
actions: {
hello: function() {
this.get('myFirstLevel').hello();
}
}
});
http://emberjs.jsbin.com/conaxaheno/1/edit?html,js,console,output