Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

ng-show is not working when ng-class is having array expression #12674

Closed
vinayk406 opened this issue Aug 25, 2015 · 10 comments
Closed

ng-show is not working when ng-class is having array expression #12674

vinayk406 opened this issue Aug 25, 2015 · 10 comments

Comments

@vinayk406
Copy link

ng-show is not working (angularjs version 1.4.4) when ng-class is having array expression

Here is the plnkr to demonstrate the issue.

http://plnkr.co/edit/qNTsC8sWS7b1u76zvfbO?p=preview

@frfancha
Copy link

In your plunker your controller is not defined, and this is the error message your got in the console

@vinayk406
Copy link
Author

Sorry for the wrong plnkr.

Here is the updated plnkr. http://plnkr.co/edit/qNTsC8sWS7b1u76zvfbO?p=preview

When we remove the ng-class expression every thing work as expected.

In the function addRemoveClassesPostDigest at line 4876, elements are added to the postDigestElements and then the classes are validated.

When the classes to be added or removed are not valid classNames, elements are not removed from the postDigestElements. Because of which function to apply the classes is never registered (line 4903)

@frfancha
Copy link

I have tried different things in your plnkr, and I was able to reproduce only combining an empty string and a null or undefined in the array. Using only null or only empty string works. If you can avoid mixing both you will by-pass the problem.
The minimum to reproduce is:
ng-class="[null, '']"
(only including angular, no controller, no css, no animate)

@vinayk406
Copy link
Author

I can't do that because the values in my case will be dynamic in nature.

This used to work with angular 1.4.3. Only with angular 1.4.4 we are facing this problem.

@Narretz
Copy link
Contributor

Narretz commented Aug 31, 2015

Looks like it's caused by 0d6fc2d
Though I'm not sure why the element with ngClass affects the elements with ngShow.

@petebacondarwin
Copy link
Member

The code is adding an element to the postDigestQueue but then never attaching the handler for removing it since it deems that no valid CSS class names were added. This blocks the subsequent ng-show directive etc from getting to their own postDigestQueue items.

I think we just need to make sure we only add to the queue if the CSS class names are valid.

I think we should ensure that the handler always gets added for valid CSS.

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Sep 1, 2015
…ements

The postDigest handler was not being added if the first element in
to modify the CSS classes contained invalid CSS class names. This meant
that subsequent valid CSS class changes were not being handled since we
were not then adding the handler for those correct cases.

Closes angular#12674
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Sep 1, 2015
…ements

The postDigest handler was not being added if the first element in
to modify the CSS classes contained invalid CSS class names. This meant
that subsequent valid CSS class changes were not being handled since we
were not then adding the handler for those correct cases.

Closes angular#12674
@petebacondarwin
Copy link
Member

I think I have a fix at #12725
@vinayk406, @frfancha and @Narretz can you take a look?

@petebacondarwin petebacondarwin self-assigned this Sep 1, 2015
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Sep 1, 2015
…ements

The postDigest handler was not being added if the first element in
to modify the CSS classes contained invalid CSS class names. This meant
that subsequent valid CSS class changes were not being handled since we
were not then adding the handler for those correct cases.

Closes angular#12674
@vinayk406
Copy link
Author

@petebacondarwin, With the changes the example in plnkr is working fine.
But the code changes in your pull request and the angular.js file which is loaded in plnkr look different.

@petebacondarwin
Copy link
Member

:-) yes I changed the fix but forgot to update the plunger.

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Sep 1, 2015
…ements

The postDigest handler was not being added if the first element in
to modify the CSS classes contained invalid CSS class names. This meant
that subsequent valid CSS class changes were not being handled since we
were not then adding the handler for those correct cases.

Closes angular#12674
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Sep 1, 2015
…ements

The postDigest handler was not being added if the first element in
to modify the CSS classes contained invalid CSS class names. This meant
that subsequent valid CSS class changes were not being handled since we
were not then adding the handler for those correct cases.

Closes angular#12674
@vinayk406
Copy link
Author

@petebacondarwin, Thanks for the fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants