dgbonomo
dgbonomo

Reputation: 153

How do you update another controller's properties and have its value update?

I created the following sample code:

http://ninjy.com:8080/ember/How%20to%20set%20a%20lower%20controller%27s%20variables/#/blah

When you click the button, it's supposed to change the templated text. It does do this, but the change isn't updated on-screen. It does work properly when you swap the value and action around: when the button is in Blah (below the line), and the template value in Application (above the line), then the value is updated on-screen successfully.

Can somebody explain why this happens this way, and how to have the value update properly?

Upvotes: 0

Views: 40

Answers (1)

intuitivepixel
intuitivepixel

Reputation: 23322

You need to provide lowercased names e.g. blah instead of Blah when requiring controllers:

App.ApplicationController = Ember.ObjectController.extend({
  needs: ['blah'],
  act: function() {
    console.log('act');
    var ctrl = this.get('controllers.blah');
    ctrl.set('myvalue', 'and this is the replacement text');
  }
});

Working jsbin.

Hope it helps.

Upvotes: 1

Related Questions