Search code examples
ember.jsember-data

Ember.js accessing model values in afterModel


There is a Question here Ember.js accessing model values from afterModel

but it doesn't exlpain how to access the value in the afterModel hook. Can someone advise?

my model:

model: function () {

  return Ember.RSVP.hash({

    accounts: this.store.find('account').then(function (account) {
    })
  });
},

Solution

  • Did you read the documentation? The model is the first parameter passed to afterModel.

    https://api.emberjs.com/ember/3.13/classes/Route/methods/transitionTo?anchor=afterModel

    On a slightly unrelated note, I wonder why you are returning Ember.RSVP.hash from the model hook. That makes the model (after being resolved) a hash containing a property accounts, which is presumably what you are interested in. That means every time you access the model you have to say model.accounts. Why not just return this.find(... itself, which would make the model itself the array of account instances which you could refer to directly as model?