Say I have two controllers, a CompaniesController and an IndexController. It turns out that all the data my Index route needs comes from the CompaniesController. So, I've specified my IndexController like this:
App.IndexController = Ember.ArrayController.extend({
needs: 'companies',
});
This works well if the CompaniesController is already initialized, but what about the first time I visit the site? CompaniesController is empty.
So, I need to initialize the data for CompaniesController from within the IndexController. How do I do this?
Use setupController and controllerFor within the IndexRoute:
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.find('company');
},
setupController: function(controller, model) {
this.controllerFor('companies').set('model', model);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With