2013-10-24 1 views
4

에 가게를 주입하지 :타다 남은 이니셜 나는 다음 초기화를 작동하지 않는 한 그 구성 요소

Ember.onLoad 'Ember.Application', (Application) -> 
    Ember.Application.initializer 
    name: 'storeToComponent' 
    initialize: (container, application) -> 
     application.inject('component', 'store', 'store:main') 

구성 요소를 매장 속성이 없습니다. 나는 수많은 것을 시도했다 :

before: 'registerComponents' 

그러나 아무것도 작동하지 않는다.

내가 뭘 잘못하고 있니?

답변

6

귀하의 구성 요소가 항상 그러므로 당신이 당신의 구성 요소에 수행하여 그 상황에서 저장소에 액세스 할 수 있습니다, 어떤 상황 (예 : 컨트롤러)에있을 것입니다 : 그러나

App.MyComponent = Ember.Component.extend({ 
    actions: { 
    foo: function() { 
     var store = this.get('targetObject.store'); 
    } 
    } 
}); 

, 구성 요소이기 때문에라고한다 분리 된 것으로 생각되면 특정 상점에서 종속성을 작성하는 대신 데이터를 전달해야합니다. 말했다 는 경우에 당신은 정말 저장소가이처럼 그 일을 시도 할 수 귀하의 구성 요소에 주입하고 싶지 :

Ember.onLoad 'Ember.Application', (Application) -> 
    Ember.Application.initializer 
    name: 'storeToComponent' 
    before: 'registerComponents' 
    initialize: (container, application) -> 
     application.register('store:main', App.Store) 
     application.inject('component', 'store', 'store:main') 

는 도움이되기를 바랍니다.

+0

최신 버전의 Ember/Ember Data의 경우 초기화 프로그램에'after : 'store''를 지정하고'application.register (store : main', App.Store)'행을 제거해야합니다. – locks

관련 문제