How can I initialize a controller from another controller that 'needs' it?

ember.js

Solution

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);
  }
});

Problem

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?

Original source