setupController (controller, model) public
A hook you can use to setup the controller for the current route.
This method is called with the controller for the current route and the model supplied by the model
hook.
By default, the setupController
hook sets the model
property of the controller to the model
.
If you implement the setupController
hook in your Route, it will prevent this default behavior. If you want to preserve that behavior when implementing your setupController
function, make sure to call _super
:
App.PhotosRoute = Ember.Route.extend({ model: function() { return this.store.findAll('photo'); }, setupController: function(controller, model) { // Call _super for default behavior this._super(controller, model); // Implement your custom setup after this.controllerFor('application').set('showingPhotos', true); } });
The provided controller will be one resolved based on the name of this route.
If no explicit controller is defined, Ember will automatically create one.
As an example, consider the router:
App.Router.map(function() { this.route('post', { path: '/posts/:post_id' }); });
For the post
route, a controller named App.PostController
would be used if it is defined. If it is not defined, a basic Ember.Controller
instance would be used.
Example
App.PostRoute = Ember.Route.extend({ setupController: function(controller, model) { controller.set('model', model); } });
Parameters:
-
controller
Controller
- instance
-
model
Object
Please login to continue.