简体   繁体   中英

How is it possible to call a different controller's method in ember.js?

Inside another controller I get the application controller as following (as it is defined via needs):

appCtrl = this.get('controllers.application');

Accessing or setting properties works fine, eg

appCtrl.set("property", true);

will trigger registered listeners.

But I am not able to call a method of the application controller, eg assume there exists function x in the application controller. Then the following call fails as appCtrl contains no function x:

appCtrl.x();

I also tried defining x as an action in the application controller and triggering from outside as following:

appCtrl.send("x");

This also did not work.

How am I supposed to call a function of the application controller from another controller?

I tried something simple and didn't seem to have a problem. Here's a JSbin:

http://emberjs.jsbin.com/borejamufo/3/edit?html,js,console,output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM