Emberjs - how to access the method of one controller from another controller '

In emberjs pre2, we could access the controller or any method in the controller from another controller in the following way:

App.get ('router') get ('') NavController method1 (); ..

Can anyone guess what the similar code for emberjs rc1 could be?

thanks

+4
source share
3 answers

Inside Controller or Route you can try

 this.controllerFor("nav").method1() 

Attention!

This was the correct answer when the question was asked, but since controllerFor out of date, check joscas answer

+3
source

Since controllerFor deprecated, I think a more correct way would be with needs:

 this.get('controllers.nav').method1() 

This requires declaring your needs for your controller:

 App.YourController = Ember.ObjectController.extend({ needs: ['nav'], .... 
+17
source

In Ember 2, this works by entering the controller that you want to access:

 export default Ember.Controller.extend({ nav: Ember.inject.controller(), }); 

Or, if you want to specify a name other than the controller name:

 export default Ember.Controller.extend({ navController: Ember.inject.controller('nav'), }); 

Then you can access methods such as:

 this.get('navController').method1() 
+2
source

All Articles