Reputation: 3414
I'm writing a component in which I need to access the current route's model; in the component's template I would like to do something like:
{{#each color in model}}
...
{{/each}}
I will use this component in different routes, with different models
How can I access the current route's model inside the component?
Ember.Component.extend({
didInsertElement: function() {
console.log(this.get('controller') //this is not the route's controller
console.log(this.get('controller').get('model')); //undefined of course
}
});
Upvotes: 5
Views: 2808
Reputation: 47367
Pass it into the component.
{{my-comp model=model foo=model bar=model}}
In the example above, within the scope of your component model
, foo
, and bar
would be the model.
Upvotes: 5