Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need to set the model on the controller when using setupController on Ember.Route?

Tags:

ember.js

I have been having some confusion in regards to the Ember.Route model vs. setupController. I have an example app here:

http://jsbin.com/ihakop/5/edit

I am wondering why it is that I need to add the following (see inline comment)

App.AppsShowRoute = Ember.Route.extend({
  model: function(params) {
    return App.LtiApp.find(params.id);
  },

  setupController: function(controller, model) {
    controller.set('reviews', App.Review.find());

    // Why is this line needed? Shouldn't it have the model
    // already on the controller?
    controller.set('model', model);
  }
});

Shouldn't the model already be on the controller?

like image 603
coderberry Avatar asked Feb 15 '23 17:02

coderberry


1 Answers

This is a good question. This behaviour was introduced with RC4. Have a look at this blog post for explanation. The recommendation of the Ember guys is to add a call to _super():

App.AppsShowRoute = Ember.Route.extend({
  model: function(params) {
    return App.LtiApp.find(params.id);
  },

  setupController: function(controller, model) {
     this._super(controller, model);
     controller.set('reviews', App.Review.find());
  }
});
like image 192
mavilein Avatar answered Feb 18 '23 05:02

mavilein