How get model in controller?

Hi there! I have model with some props.
name: DS.attr(),
description: DS.attr(),
stats: DS.attr(),
someValue: Ember.computed(‘stats’, function() { return data })

But, how i can get in controller property ‘someValue’ ?

Hey Jobsboris, it is a good start, but a Ember works a little bit differently. You can learn all the basics from this tutorial http://yoember.com or form the official guide: https://guides.emberjs.com/v2.5.0/tutorial/ember-cli/

Basically, you have the model, with name, description and stats, but you need a route also, where you download data from your server (from a backend) and that route will provide data (a model property) for you in your template. Follow through those tutorials, and everything will be more clearer and super simple after. Have a great learning.

1 Like

Thanks! I can link model and controller using a template by using the action.

I struggled with this for a while…

In my item router I have

model: function(params) {
 return this.store.fetchById('item', params.item_id);
},

My item model is something like:

size: DS.attr('string'),
colour: DS.attr('string'),

Then in my item controller, I have

itemColour: Ember.computed.alias("model.colour"),

So I now have the colour property of the model available in the controller…

Hope that helps…

2 Likes