mercredi 16 août 2017

Ember.js: accessing computed alias from component's javascript

I currently have a model that contains a computed alias, as follows:

model: DS.belongsTo('device-model'),
manufacturerName: Ember.computed.alias('model.manufacturer.name')

I then have a component that is invoked as follows:



Now, in the component's Handlebars template, I can easily access the computed property with , however in my-component.js I am having trouble getting it to work. I have tried with:

console.log(this.get('model').get('manufacturerName'))

However, the output is undefined. So far, the only way I can get the manufacturer name from my-component.js is:

this.get('model').get('model')
.then((model) =>{
  return model.get('manufacturer')
})
.then((manufacturer) => {
  console.log(manufacturer.get('name'))
})

So, I'm wondering what is the Handlebars template doing that I can't do in its javascript counterpart? It seems like the Handlebars template is following through the promise, whereas I have to do it manually when it comes to the component's javascript.

Thank you!




Aucun commentaire:

Enregistrer un commentaire