I'm puzzled why how the Route and Controller are affecting the default Model. Here is an example.
App.ApplicationRoute = Ember.Route.extend({
setupController: function(controller, model) {
this._super(controller, model);
console.log(model); //returns undefined
controller.set("title", "Page title");
}
});
This code snippet above works without errors; the template prints {{title}} as expected. Note that the model is "undefined."
App.ApplicationRoute = Ember.Route.extend({
setupController: function(controller, model) {
this._super(controller, model);
console.log(model); //returns undefined
controller.set("title", "Page title");
}
});
App.ApplicationController = Ember.ObjectController.extend({});
The code immediately above throws an error ...
(Error while processing route: index Assertion Failed: Cannot delegate set('title', Page title) to the 'content' property of object proxy : its 'content' is undefined.)
... and yields a blank page. The solution is to return a model (blank object) or use a Controller (default behavior) instead of an ObjectController. Could someone explain this peculiar circumstance? Why doesn't Ember assume an empty object when using an ObjectController? Is it assuming the object will be passed in or retrieved from the store or server?
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return {};
},
setupController: function(controller, model) {
this._super(controller, model);
console.log(model);
controller.set("title", "Page title");
}
});
App.ApplicationController = Ember.ObjectController.extend({});