Dougui
Dougui

Reputation: 7232

How to use store in an initializer

I want to use the store in an initializer to I tried to do this :

export function initialize(application) {
  application.inject('controller', 'store', 'service:store');
  this.store.createRecord('model');
}

export default {
  name: 'modify-models',
  initialize
};

With this, this.store is undefined.

As in the doc, I tried var store = application.lookup('service:store'); but application.lookup is undefined.

I also tried var store = Ember.inject.service('store'); but store is undefined.

I can't find the right way. What's the solution?

Upvotes: 2

Views: 402

Answers (1)

locks
locks

Reputation: 6577

You need to make sure it is an instance initializer, and you need to make it run after ember-data:

export default {
  name: 'modify-models',
  after: 'ember-data',
  initialize
};

Upvotes: 6

Related Questions