Search code examples
ember.jsember-old-router

How to get an instance of a controller in Ember.js?


I'm trying to access an instance of a controller that has been wired automatically using App.initialize();

I've tried the below but it returns a Class not an instance.

Ember.get('App.router.invitesController')


Solution

  • This answer works with RC1/RC2.

    Now you can use the needs declaration in order to make the desired controller accessible. Here's an example:

    Suppose I want to get something from my SettingsController from within my ApplicationController. I can do the following:

    App.SettingsController = Ember.Controller.extend({
      isPublic: true
    });
    
    App.ApplicationController = Ember.Controller.extend({
      needs: 'settings',
      isPublicBinding: 'controllers.settings.isPublic'
    });
    

    Now in the context of my ApplicationController, I can just do this.get('isPublic')