Reputation: 6185
I'm building an app in Ember with EmberCLI.
In my top navigation (controllers/navigation/top.js) I have an action that is triggered on a button click. This action should open the left navigation (controllers/navigation/left.js).
My top navigation controller:
import Ember from "ember";
export default Ember.Controller.extend({
actions: {
toggleMenu: function() {
// I need to call toggleProperty on the left navigation controller.
[leftNavigationController].toggleProperty('visible');
}
}
});
How to get another controllers instance to call a method like toggleProperty
?
Upvotes: 1
Views: 163
Reputation: 47367
in a controller you would use needs
and then get the controller and call it
App.FooController = Ember.ObjectController.extend({
needs:['bar'],
blah: function(){
var barController = this.get('controllers.bar');
barController.toggleProperty('visible');
}
});
http://emberjs.jsbin.com/dofedehi/2/edit
Upvotes: 3