ember.js - How can I initialize a controller from another controller that 'needs' it? -


say have 2 controllers, companiescontroller , indexcontroller. turns out data index route needs comes companiescontroller. so, i've specified indexcontroller this:

app.indexcontroller = ember.arraycontroller.extend({     needs: 'companies', }); 

this works if companiescontroller initialized, first time visit site? companiescontroller empty.

so, need initialize data companiescontroller within indexcontroller. how do this?

use setupcontroller , controllerfor within indexroute:

app.indexroute = ember.route.extend({   model: function() {     return this.store.find('company');   },   setupcontroller: function(controller, model) {     this.controllerfor('companies').set('model', model);   } }); 

Comments