In emberJS, I have a model with an object property called style. I can set it’s properties using test.setPath('style.a'). I am trying to observe the style object but my observe callback is not firing.
You can see the code here.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This basic misunderstanding of how Ember observers work is a common mistake. In your example, you have the following in your view
test:The
test.styleproperty is pointing to anEmber.Objectandtest.setStyle()is changing the value of a given property on thatEmber.Object. A common mistake is thinking that resetting a property to the same object will call any observer on it as you’re doing with this line:this.set('style', style). Well that’s not how Ember observers work. Observers in Ember are fired automatically when the actual value of a property has changed. Setting thestyleproperty to itself doesn’t change the objectstyleis pointing to, thus it doesn’t change the value of the property (actually that code does nothing at all). In this case it looks like you need to tell Ember manually that thestyleproperty has changed. You can do that by callingnotifyPropertyChange().Look at the following modified code for
setStyle:This will cause your observer to fire.