0
我有一個需要存儲和路由器的餘燼組件。我正在嘗試使用Ember.inject.service
注入它們。它適用於當我注入商店,但不是路由器:Ember依賴注入不能在Ember中使用路由器1.11
import Ember from 'ember';
const MyComponent = Ember.Component.extend({
store: Ember.inject.service('store'),
routing: Ember.inject.service('-routing'),
classNames: ['my-component'],
schema: Ember.computed('store', 'routing', function schema() {
// This works. Shows up when I log it.
const store = this.get('store');
// This doesn't
const routing = this.get('routing');
// return schema from store. This works.
}),
});
export default MyComponent
我在Ember版本1.11.3。我錯過了什麼嗎?
您是否檢查過包裝中是否含有此物質? 'ember-routing/lib/services/routing.js'也許你只是想念這個文件。另外,你有什麼錯誤嗎?例如,你是否嘗試從初始化程序注入? – reillyethan
@reillyethan:什麼包?在燼中構建自己?沒有錯誤。目前我正在注入組件初始化。 – BarFooBar
我以爲也許路由服務安裝不正確或不正確,但沒有任何意義。那麼,我不知道爲什麼它不起作用。 Docs表示這項服務是私密的,但可以打開。我不知道這是什麼意思,你可以看到[這裏]的評論(https://github.com/emberjs/ember.js/blob/v2.7.0/packages/ember-routing/lib/services/ routing.js#L13)也許它不是像商店那樣開放或者不適合 – reillyethan