Note: This article is based on Ember.js 1.4.0
In Ember.js, routing (route) sets the controller (Controller) property through the Setupcontroller method:
The code is as follows |
Copy Code |
App.applicationroute = Ember.Route.extend ({ Model:function () { return {' user ': ' Chen San ', ' blog ': ' http://www.111cn.net/'}; }, Setupcontroller:function (Controller, model) { Controller.set (' model ', model); <-here, we assign the model to the Model property of the Controller } }); |
In the front-end template, you can refer directly to the properties of the object:
The code is as follows |
Copy Code |
<script type= "Text/x-handlebars" > User {{User}} 's blog address is {{blog}} </script> |
The page renders the result as
The user Chen San's blog address is http://www.111cn.net
But if you check the properties of Applicationcontroller with Ember.js Inspector2, the following figure:
Ember.js Check Device
We do not see a property called model, and instead, there is a content attribute that contains what we assign to the model.
What if you change the model to content in Setupcontroller?
The code is as follows |
Copy Code |
App.applicationroute = Ember.Route.extend ({ Model:function () { return {' user ': ' Chen San ', ' blog ': ' http://www.111cn.net/'}; }, Setupcontroller:function (Controller, model) { Controller.set (' content ', model); <-this time, we assign the model content to the content attribute of the Controller } }); |
Practice has proved that content and model properties are equivalent.
To be more precise, model is just an alias of content set by EMBER.COMPUTED.ALIAS3 4:
The code is as follows |
Copy Code |
Model:Ember.computed.alias (' content '), |
As for why to set such an alias, you can look at a discussion on Github 5.