Access Store from within Component?

Is (and if so - how?) it possbile to access store data from a component? I save some strings which I load in the application router like so:

//routes/application.js    
import Ember from 'ember';

export default Ember.Route.extend({

   model : function() {
       var host = this.store.adapterFor('application').get('host');
       var namespace = this.store.adapterFor('application').get('namespace');
       var route = this;
       return new Ember.RSVP.Promise(function (resolve) {
           Ember.$.getJSON(host + '/' + namespace + '/strings/de').then(function (data) {
               route.controllerFor('application').set('model', data);

               //route.transitionTo('index');
               resolve();
           });
       });
   }
});

Since I’m pretty new to ember I don’t really know if this is the correct way anyways… So now is the question - how to access this store data in my component?

//components/t-string.js
import Ember from 'ember';

export default Ember.Component.extend({
    tagName: '',
    getString: function () {
        var key = this.get('key');
        // controller? store? how to get it?

        var string = ''; // from store...


        return string;
    }.property()
});

@mkconn

check this

Cool! DI solved it for me :slight_smile:

Can you be more specific? What is DI?

He refers to Dependency Injection (DI). In this case it means injecting the store into the component

export default Ember.Component.extend({
  store: Ember.inject.service(),
2 Likes