Can't update template from controller


#1

I need to update template from action. But I use two controllers on one page.

In my template I show a text:

{{myText}} My controller:

export default Ember.Controller.extend({
   myText: 'Hi',
   init: function()  {
      ....
   },
   actions: {
    reload: function() {
        this.set('myText', 'Bye');
    }
   }
   ...

I change it from another controller from someFun:

export default Ember.Controller.extend({
    needs: ['another'],
    someFun: function() {
        this.get('controllers.another').send('reload');
    }
});

It calls reload action (I tested). But it doesn’t change template. It still shows Hi but should change to Bye. Also reload action calls init.

Ember version is 1.8


#2

Hmm, seems like a good question for StackOverflow. Would you mind posting it there along with a Twiddle showing your issue?


#3

Hm…how are you invoking this someFun function?

By default .send does not creates a runloop. This means if you are invoking the function directly from console, the change would not get flushed to the template. Try wrapping the content of someFun in a runloop.

...
someFun: function() {
  Ember.run.join(this, function() {
    this.get('controllers.another').send('reload');
  });
}
...