Martin Krämer
Martin Krämer

Reputation: 577

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, e.g.

appCtrl.set("property", true);

will trigger registered listeners.

But I am not able to call a method of the application controller, e.g. 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?

Upvotes: 0

Views: 56

Answers (1)

Sam Selikoff
Sam Selikoff

Reputation: 12694

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

Upvotes: 1

Related Questions