Access store from component

后端 未结 7 745
离开以前
离开以前 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:58

    The current ember-cli way to do this appears to be with an initializer. Very similar to the @Sly7_7 answer.

    To get a basic model use:

      ember g initializer component-store-injector
    

    Then edit this to:

    // app/initializers/component-store-injector.js
    
    export function initialize(container, application) {
      application.inject('component', 'store', 'store:main');
    }
    
    export default {
      name: 'component-store-injector',
      initialize: initialize
    };
    

    I believe this will add the store to all components.

    Stolen from https://github.com/ember-cli/ember-cli-todos

提交回复
热议问题