-
Notifications
You must be signed in to change notification settings - Fork 27.5k
When interpolated class attribute changes, classes from ng-class are not merged in #1016
Comments
Why do you want to use both the interpolation and ngClass directive to control the value of the class attribute? Can you use just one or another? The provided patch works, but introduces performance issues and unwanted dependency between $compile service and ngClass directive. So we can't merge it as is. Unless we can find a valid reason why both interpolation and ngClass should be able to work together, I'm inclined to say that we are not going to fix this because the fix would complicate the code unnecessarily. If we do find a valid reason to support this, then we should just change the watch expression of the ngClass directive from |
The reason is that I want to apply one class conditionally (either applied or not) and others based on the value of a string variable. Like this: I also see now that my solution wasn't very good :) This seems to work and is more like what you suggest (I think)
which does not require changes to compile.js, and fewer changes to ngClass.js (don't need to inject $interpolate) Would that also be inefficient if say both class and ng-class change in the same digest cycle or something? |
I pushed the new solution, so if you find my motivation reasonable and the code easy enough, it's there if you want it :) |
Experienced this issue with AngularJS v1.1.0 |
Open http://jsfiddle.net/ADukg/224/
Set ngclass to true by clicking the first button. Note how the ngclass text turns green.
Then set class to true by clicking the second button. Note how the ngclass text turned red again.
So:
Result: div element has
class="static class"
, thus coloring "class" green and "ngclass" redExpected result: div element has
class="static class ngclass"
, thus coloring both "class" and "ngclass" greenI have a (maybe very ugly) fix for this, which involves:
attr[name]
toundefined
whenname === 'class'
inaddAttrInterpolateDirective()
$watch
:ing$interpolate(attr['class'])
inclassDirective()
and reapplying the "ngclasses" when it changes.The reason I'm not totally sure about this solution is that I don't know why you're setting attributes to
undefined
inaddAttrInterpolateDirective()
, and I'm not sure what consequences it will have if we don't.What do you think about this?
I can post some more code later, but I want to see if all tests pass first.
The text was updated successfully, but these errors were encountered: