Vivendi
Vivendi

Reputation: 21007

Update style attribute when ngStyle is updated

I have a div with an ngStyle attribute. Initially the div looks fine. But when I update a property that is used inside the ngStyleattribute, then the style tag isn't updated. So the changes aren't reflected to the div.

Here's an example of what I mean: http://plnkr.co/edit/YQIxJYEFWwbxiXr4HBwY?p=preview

Initially the div is green. When you click on the button below it then you can see that the ngStyle attribute is updated with the #ff0000 (red) color. But the style attribute doesn't get updated.

Is there any way to force angular to update the style attribute again?

Please note: In my real scenario the div has a lot more style properties. And the div also has a <p> tag which has style properties etc.

I don't want to change the way the ngStyle looks right now. I want to know if it's possible to forcefully update the style attribute when I use this method.

Upvotes: 2

Views: 2045

Answers (1)

Wildhoney
Wildhoney

Reputation: 4969

Don't wrap the {{bg}}instead just specify it as bg: http://plnkr.co/edit/F1fwgWn48fgZJT1mBiaQ?p=preview

Upvotes: 5

Related Questions