This two are defined on different ember objects - model
property on controller and modelFor
method on route.
First of all, the model
property, and executing it as this.get('model')
only gets the object that is already set on the model
property in controller. It means, that it gets anything that was set up during the setupController
hook in route. You cannot fetch any data from API using this statement. Moreover, it allows you only to get the object that was set on current controller (this
scope).
When is it set up?
In setupController
hook. The life-cycle of route first resolves all model-related callbacks (beforeModel
, model
and afterModel
). After that, it executes setupController
with these arguments: (controller, model)
. It means that it has access to all that resolved from model
hook and the current controller
instance. By default, the setupController
sets the model
on controller.model
property:
controller.set('model', model);
You can override that with your custom code and e.g. set your model on myModel
property - it depends on you. But if you want to get your model in your controller code, you have to always query the property you set your model on.
How #modelFor works?
modelFor
is defined on routes instances and allows you to get the model
hook result from any route in your application. You can use it in your setupController
hook as follows:
controller.set('model', this.modelFor('myOtherRoute'));
This behaviour can be considered as improving consistency across the app - it explicitly says that in current route and controller you use the same data as in myOtherRoute
.
How does it work? It queries myOtherRoute.model
property, that stores the model
resolved data of that route. The implementation is fairly simple - it looks up your container
(global object that stores your routes, controllers, components, etc.) for the route named myOtherRoute
and gets it model
property.