Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngClass array syntax behavior not according to documentation #8578

Closed
Almar opened this issue Aug 12, 2014 · 9 comments
Closed

ngClass array syntax behavior not according to documentation #8578

Almar opened this issue Aug 12, 2014 · 9 comments

Comments

@Almar
Copy link
Contributor

Almar commented Aug 12, 2014

Is this a bug or should the documentation be updated?

Documentation:

If the expression evaluates to an array, each element of the array should be a string that is one or more space-delimited class names.

However if an array element has multiple, space-delimited, classes only the last one appears to be applied. This behavior can be seen in the example in the documentation for ngClass.

Moreover; the example code for ngClass also suggest that an array element can only have one class - the placeholder text is "Type: bold, strike or red".

@caitp
Copy link
Contributor

caitp commented Aug 12, 2014

http://plnkr.co/edit/q87uzBJuk6dWaOpodO4b?p=preview seems to work as expected (or please provide a reproduction, in other words)

@Almar
Copy link
Contributor Author

Almar commented Aug 12, 2014

@caitp, you're right; your example works as expected. I'll close this issue.

The example in the documentation remains confusing to me though; it allows you to change an element in the array. When the element has one class it works. When specifying more than one class for the element only the last class seems to be applied.

@Almar Almar closed this as completed Aug 12, 2014
@caitp
Copy link
Contributor

caitp commented Aug 12, 2014

hmm I see, I'll take a look

@caitp caitp reopened this Aug 12, 2014
@caitp
Copy link
Contributor

caitp commented Aug 12, 2014

Okay, it actually looks like this is a jqLite bug, setClass() does not handle the multi-class case well. I think this is valid

edit s/jqLite/ngAnimate/ /cc @matsko

@matsko
Copy link
Contributor

matsko commented Aug 12, 2014

OK I'll assign it to myself then and I'll fix it.

@caitp
Copy link
Contributor

caitp commented Aug 12, 2014

What happens is, when you type the s key in bold s, you already have the bold class, and jqLite thinks you want to add bold s and remove bold (the removal follows the addition, so this cancels out the bold that was added).

It's probably more performant to fix this in ngClass, though

@matsko
Copy link
Contributor

matsko commented Aug 12, 2014

addClass, removeClass and setClass in Animate have a similar bug anyway. It would be good to see everything together.

@btford btford added this to the 1.3.0 milestone Aug 19, 2014
@danteregis
Copy link

I have encountered this bug while working on an application and this plunker reproduces it: http://plnkr.co/edit/FEkuhH

@matsko
Copy link
Contributor

matsko commented Nov 7, 2014

OK cool. I will have a look on Saturday. Thank you.

lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Jan 6, 2015
Handles multi-class definition as an element of an array

Closes angular#8578
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.