Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

Can anybody suggest what could be the similar code for emberjs rc1?

Thanks

like image 584
Mohammad Nazmuz Salehin Avatar asked Nov 30 '22 01:11

Mohammad Nazmuz Salehin


2 Answers

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

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

It requires declaring your needs in your controller:

App.YourController = Ember.ObjectController.extend({
  needs: ['nav'],
  ....
like image 175
joscas Avatar answered Dec 05 '22 23:12

joscas


Inside a Controller or a Route you can try

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

Attention

This was correct answer when the question was asked but since controllerFor is deprecated, please check the answer by joscas

like image 38
Mudassir Ali Avatar answered Dec 06 '22 00:12

Mudassir Ali