Tim Jahn
Tim Jahn

Reputation: 1174

How do I set the value of a property in Controller A from within Controller B?

I have two controllers: controller A and controller B. Controller A has a property called "total_price" which has a numeric value. I'd like to set the "total_price" value of Controller A to 0, from within controller B.

I know needs (http://emberjs.com/guides/controllers/dependencies-between-controllers/) lets you access other controller properties but I can't see anything in the documentation about setting another controller's properties.

How can I accomplish this? Thanks!

Upvotes: 0

Views: 134

Answers (1)

rallrall
rallrall

Reputation: 4770

If you use the needs api to get controller A, you can set values on that controller like you normally would.

NerfController = Ember.Controller.extend({
    needs: ['other'],

    setValueInOther: function(newValue) {
        this.get('controllers.other').set('value', newValue);
    }
});

Upvotes: 1

Related Questions