I have big trouble with EmberJS. I'm using Ember.RSVP.hash to load multiple of models like this:
route:
model() {
const self = this;
return Ember.RSVP.hash({
test: 'sample text'
}).then((hash) => {
return Ember.RSVP.hash({
test: hash.test,
});
}, self);
}
Then in my controller I'm trying to access this model param like this:
controller:
export default Controller.extend({
init() {
console.log(this.get('model.test');
}
My console should log 'sample text' but unfortunately I'm getting 'undefined'
Is this caused by init method I used? I want to notice that I need to have access to this param immediately after loading this route page.
Use setupController
hook in route.js it will be called after model hook , so you will get controller
and model
instance in the argument, so you can get access to model properties and set controller properties based on model
.
setupController(controller,model)
{
controller.setProperites(model);
//you can do anything with controller and model instance
}
init
method will be called before you model
hook finishing the execution so you can not access it this.get('model.test')
like you did.