Nadeem Khedr
Nadeem Khedr

Reputation: 5313

When there is setupController the model value returned from the model hook is null

Why when adding setupController to a route the model value returned from the model hook is null ?

http://jsbin.com/pahuno/1/edit

I know i could work around it by setting up the model value in the setupController but I want to understand what is the problem

Upvotes: 0

Views: 144

Answers (1)

mistahenry
mistahenry

Reputation: 8744

Working JSBin

When you use a hook, such as setupController or renderTemplate, you are preventing Ember from handling the default case. Make a call to the default method:

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return ['red', 'yellow', 'blue'];
  },
  setupController: function(controller, model) {
    this._super(controller, model);
  }
});

From a comment in the Ember source:

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:

Upvotes: 3

Related Questions