Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ember js component observer does not work

I have a scenario in emberjs component where the observe does not get hit. I figured out the reason as "the component is not yet inserted when the component property being observed is set."

My questions is, couldn this be handled in a better way in ember js?

Better explanation can be found in the below jsbin`s.

Not working Scenario

Working scenario

like image 334
wallop Avatar asked Jan 06 '15 16:01

wallop


1 Answers

You can specify .on('init') to force the observers to run right after initialization; otherwise like @Kingpin2k mentioned - they don't run

App.TextboxDisplayComponent = Ember.Component.extend({
  displayText: '',        

  boundProperty: '',

  observeBoundProperty: function () {
    this.set('displayText', this.get('boundProperty'));        
  }.observes('boundProperty').on('init')
});

Your (non-)working example here

like image 137
Kalman Avatar answered Nov 06 '22 09:11

Kalman