-
Notifications
You must be signed in to change notification settings - Fork 27.5k
[1.2.3] bug in ng-class-odd with multiple words in class name #5271
Comments
http://jsfiddle.net/QSr2F/1/ --- Works just fine |
@caitp Thanks for reply. It seems the behavior changed since 1.2.2. <span class="ui message" ng-class-odd="'odd'" ng-class-even="'even'"> And here is mine: <span ng-class-odd="'ui odd message'" ng-class-even="'ui even message'"> Does it mean I have to move the common parts in the class to a separate class. It's generally not a problem if the class names are static. However, if they are dynamic, it's going to be tricky to figure out the 'common parts'. Don't know if this is intended as a new feature, or it's just a bug? |
I don't believe this is a bug, I'm fairly sure this is part of a change to help ngAnimate + ngClass not be broken. Matias would know better, but I expect that's what you'd find if you used git bisect to see where the change happened. |
According to the docs this should work like @elgs used it: http://docs.angularjs.org/api/ng.directive:ngClassEven says "The result of the evaluation can be a string representing space delimited class names or an array." Same for |
Thanks @caitp, at least your code is a work around for me. OK, if this is not a bug, at least when the code is written like mine, the ng-class-odd behaves semantically inconsistently. Is my statement fair? |
I am not contesting that @tbosch, and I think that it is fair to expect this behaviour @elgs. However, if this is related to the ngAnimate + ngClass brokenness from a while ago, I'm not sure we can just revert the change, that would be bad :( So a fix would be a bit more involved. I don't want to ping le animation expert since he seems to be busy with other things at the moment, but he might have an idea of how to solve it quickly |
+1 to @tbosch. It's ok for me to use @caitp 's code as a workaround now, and I don't expect you to revert the change just in order to fix this problem. I just hope the devs are aware of this issue, and some day it can be fixed. I think this is going to be a problem when the class names are dynamically generated. |
elgs: you should be able to just use the regular |
@caitp yes, that's right. However, what if when the odd and even classes are dynamically generated at run time, and they happen to share some common words? |
Your goal for the time being should be to keep the directives from fighting with each other, I think. Try not to duplicate class names across them |
@elgs you'll run into problems if your code is removing and adding the same CSS class during two animations. The ideal code for is just as provided above: <span class="ui message" ng-class-odd="'odd'" ng-class-even="'even'"> |
I'm so on this. |
Fixed with @btford's amazing patch: http://jsfiddle.net/QSr2F/7/ |
The basic approach is to introduce a new elt.data() called $classCounts that keeps track of how many times ngClass, ngClassEven, or ngClassOdd tries to add a given class. The class is added only when the count goes from 0 to 1, and removed only when the count hits 0. To avoid duplicating work, some of the logic for checking which classes to add/remove move into this directive and the directive calls $animate. Closes angular#5271
The basic approach is to introduce a new elt.data() called $classCounts that keeps track of how many times ngClass, ngClassEven, or ngClassOdd tries to add a given class. The class is added only when the count goes from 0 to 1, and removed only when the count hits 0. To avoid duplicating work, some of the logic for checking which classes to add/remove move into this directive and the directive calls $animate. Closes #5271
I believe this is a new bug introduced in Angularjs 1.2.3, please see the following JSFiddle.
http://jsfiddle.net/QSr2F/
When there are multiple words in the ng-class-odd/ng-class-even, the first and second rows are ok, starting from the third row, the class for the odd rows is wrong, while the class for the even rows is right.
There is no such problem when the class names are single word (with no spaces in between).
The text was updated successfully, but these errors were encountered: