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
}
});
In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.
Ember components are used to turn markup text and styles into reusable content. Components consist of two parts: a JavaScript component file that defines behavior, and its accompanying Handlebars template that defines the markup for the component's UI. Components must have at least one dash in their name.
A Service is an Ember object that lives for the duration of the application, and can be made available in different parts of your application. Services are useful for features that require shared state or persistent connections. Example uses of services might include: User/session authentication. Geolocation.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With