Access store from component

后端 未结 7 758
离开以前
离开以前 2020-12-08 04:40

i have a component and when user click on component it add some value to store,i try to use this way but i get an error :

OlapApp.MeasureListItemComponent =         


        
7条回答
  •  粉色の甜心
    2020-12-08 04:50

    I don't know if components are intended to be used such a way. But if you want, I think you can declare an initializer and inject the store into all components.

    Ember.onLoad('OlaApp', function(OlaApp) {
      OlapApp.initializer({
        name: 'injectStoreIntoComponents',
        before: 'registerComponents',
        initialize: function(container, application){
          container.register('store:main', App.Store);
          container.injection('component', 'store', 'store:main');
        }
      })
    });
    

    Here is a contrived but working example: http://jsbin.com/AlIyUDo/6/edit

提交回复
热议问题