As read in the documentation, a controller should never call method or change properties on its associated view but instead the view should bind the state of its associated controller.
Having this:
App.MyController = Ember.Controller.extend({
myViewVisible:false,
toggleViewVisibitity:function(){
this.set('myViewVisible', !this.get('myViewVisible'));
}
}
App.MyView = Ember.View.extend({
isVisible:function(){
return this.get('myViewVisible');
}.observes('myViewVisible')
}
When I call toggleViewVisibility from another controller, nothing happens in the view.
How can I make it right?
Thanks in advance
It should work this way:
App.MyController = Ember.Controller.extend({
myViewVisible:false,
toggleViewVisibitity:function(){
this.set('myViewVisible', !this.get('myViewVisible'));
}
}
App.MyView = Ember.View.extend({
isVisible:function(){
return this.get('controller.myViewVisible');
}.property('controller.myViewVisible'),
// even shorter version of the above
isVisible : Ember.computed.alias("controller.myViewVisible")
}
Needed changes to your code:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With