Could someone lend me a hand with this concern?
I currently have EmberJS 3.4 version and in my route, the code looks like:
export default Route.extend({
model(){
const items = [{price: 10}, {price: 15}]
return items
},
});
However, in the controller, the model returns undefined:
export default Controller.extend({
init(){
console.log(this.model); //returns undefined
console.log(this); //has the model object as a property
},
})
Refer to this image for the output:
Even though this.model returns undefined, when accessing it within a computed property, why isn't it still undefined?
export default Controller.extend({
subtotal: computed('this.model', function(){
return this.model.reduce((acc, item) => {
return acc + item.price
},0) // return 25
}),
})