How to get Ember Data's "store" from anywhere in the application so that I can do store.find()?

HaoQi Li picture HaoQi Li · Sep 12, 2013 · Viewed 14.1k times · Source

With the recent update, I know that in routers and controllers, I can easily just do this.store.find('model'). However I have some functions that need to call find that are not in routers and controllers. So how can I get an instance store from anywhere in an Ember App?

I know worst comes to worst I can do App.__container__.lookup('store:main'), but I'll try to stay away from that.

Answer

Jeremy Green picture Jeremy Green · Sep 12, 2013

The TRANSITION doc says that you can do this to inject the store into components :

App.inject('component', 'store', 'store:main');

You might be able to change 'component' to 'view' or to 'model', but I'm not sure about that.