I am quite new to ember and don't really get the difference between two types of syntax. Where and in which situations should i use one or another. I.e. Which one is more suitable for usage in Routes and which one for Controllers.
this.get('model')
As opposed to
this.modelFor('artists/show')
By default, setupController will set the model property of controller to the value returned from model hook of the route. You could also you it to, for example, set the model of another controller, or set some initial controller state that depends on the model.
What are Computed Properties? In a nutshell, computed properties let you declare functions as properties. You create one by defining a computed property as a function, which Ember will automatically call when you ask for the property. You can then use it the same way you would any normal, static property.
It is the main interface you use to interact with Ember Data. In this case, call the findAll function on the store and provide it with the name of your newly created rental model class. import Route from '@ember/routing/route'; export default Route. extend({ model() { return this.
this.get('model') fetches the model from the current controller scope.
this.modelFor('artists/show') fetches the model that would be in scope at the specified route.
this.get('model') //controller call
this.modelFor('someRoute') //route call
In Ember, a routes setupController
hook by default performs this one line of code:
setupController: function(controller, model){
controller.set('model', model);
}
This takes whatever is returned from the model
hook and sets the controller's model
property with this value. From within the controller, this.get('model')
is the proper way to access this model. Also, a developer can override this hook and do something different, like set model
equal to some child property of what is returned from the model
hook (controller.set('model', model.prop)
. This is worth noting, because when you call this.modelFor
from another route, you DO NOT get the route's associated controller's model that is set by setupController
. You get whatever is returned from the model
hook, which under the covers is the route's currentModel
property if I remember correctly.
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