-
Notifications
You must be signed in to change notification settings - Fork 27.4k
When I mix class + expression with ng-class, the ng-class is not being compiled if expression is broken or fails to return anything #9109
Comments
I fact it doesn't happen when you say it does. Here is the updated fiddle: http://jsfiddle.net/ExpertSystem/4z4s4hhs/15/ BTW, this seems to have been broken in |
Let's assume the following html:
evaluated against the following context: The complexity of this is kind of beyond my reach, but I'll just post my observations from trying to track the problem down (in hope of saving someone some time): (A)
This is the expected outcome.
This happens (or so I say), because attribute-interpolation interpolates the string (B)
(CCing @IgorMinar because he seems to be the one introducng (C)
(D) Generally, I think attribute interpolation should check (how?) that there has been no modification to the original template string (based on which the new value has been computed). If the original template string has been modified, then the computed value is useless and interpolation should rerun. I am not sure this is indeed the problem, I am just speculating here.
*: In order for this to be feasible, there needs to be a way to extract the template string from the current interpolated string. I.e.:
Oooor...maybe I am overthinking this. The solution might be totally different. Anyway, sorry for the large comment and let me know if I can provide any further help :) |
I am impressed. Thanks for the in-depth explanation. I am working around the issue by making sure I only bind expressions that I am sure will return, or avoiding mixing |
@seefeld: The problem arises only when So, avoiding mixing |
@gkalpak's interpretation of the issue looks right --- I'm not sure why we're deferring invokation of the listener (this seems a bit weird). I'd like to get this fixed properly, but I don't want to write a patch until I know specifically what we're doing this for |
Escalate! |
@gkalpak sorry if it's not a best place to ask, but is there any difference between using of |
@havenchyk, I don't think there is any difference in performance, but it there are differences:
Bottom line(s): |
@gkalpak thanks a lot! |
FWIW, I am encountering this bug, but only when there is an ng-if attribute on the element with the ng-class + (2 or more) interpolated class values. I can confirm that it occurs only when there is more than 1 interpolated values in the class attribute. |
This appears to be fixed in 1.4: http://jsfiddle.net/d2gcvd3g/ |
And in 1.3.18: http://jsfiddle.net/1guyaxob/ |
Nice :) Thx @petebacondarwin for verifying ! The general problem still exists though; it's more explicitly tracked in #12813. |
This issue is not fixed untill latest 1.4.7 version. I'm using Angular 1.4.7 (also tested in 1.4.5 and 1.4.6) — I have the same issues as described in this topic — if I have 2 or more (In fact, they are not working only in first digest cycle — after the scope is updated second time (after some action which updates the scope, for example), everything works as expected :) So, here All functions return
|
You can use |
You can use ng-class="{'classOne': true, 'classTwo': false, 'items-tier3-for-reorder-{{firstTierIndex}}-{{secondTierIndex}}-{{thirdTierIndex}}': true}" This works for me |
I noticed when I mix
ng-class
withclass + expression
(class="something-{{data}}"), if the expression fails to return anything (does not exist for example), than theng-class
will not get compiled at all.Also, it only happens when the broken expression is in the middle of the
class
<div class="stuff-{{ok}} another-{{nothing}} third-{{ok}}"></div>
.Here is fiddle example: http://jsfiddle.net/seefeld/4z4s4hhs/6/
The text was updated successfully, but these errors were encountered: