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

Merging ng-class inside & outside element directive fails #15199

Closed
thany opened this issue Sep 29, 2016 · 2 comments
Closed

Merging ng-class inside & outside element directive fails #15199

thany opened this issue Sep 29, 2016 · 2 comments

Comments

@thany
Copy link

thany commented Sep 29, 2016

Do you want to request a feature or report a bug?
A bug

What is the current behavior?
An error:

[$parse:syntax] Syntax Error: Token ',' is unexpected, expecting []] at column 27 of the expression [{ selected: true } [ 'foo', 'foo-' + selection ]] starting at [, 'foo-' + selection ]].

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo
Yes yes, of course. Summary: the ng-class directive on a custom element directive (i.e. when using it in a page template) is not properly merged with the an ng-class directive on the root element of that custom directive (i.e. in the directive's own template).

See this plunk: http://plnkr.co/edit/bzo67zDRi6PRmDXJHYf5

What is the expected behavior?
When attributes are going to be merged from the directive to the directive's root element, it should do so not simply by concatting the attributes together, but by merging contextually. In case of ng-class, it should merge classes seperately.

What is the motivation / use case for changing the behavior?
I want to be able to have some classes set dynamically inside the directive on its root element, but still be able to dynamically add classes from outside the directive as well.

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
1.5.8 on Firefox latest, Windows 10. I seriously doubt that browser+OS has anything to do with it, but you never know. I have no idea if this has ever worked, I suspect it hasn't. It also doesn't work in the snapshot release.

Other information (e.g. stacktraces, related issues, suggestions how to fix)
The above example demonstrates that Angular tried to concat the definition of an object with an array. This might prove to be challenging to resolve. But, the same behaviour (a similar error) occurs when the instances of ng-class are both an object, or both an array. Two objects or two arrays are relatively simple to merge.

@thany
Copy link
Author

thany commented Sep 29, 2016

Well, I just discovered something odd.

The ng-class added on the directive in a page template isn't being parsed at all. It's copied to the directive's root element, but it's never doing anything other than just sit there.

That might explain why the above behaviour is happening in the first place. It's seeing the ng-class as a plain vanilla attribute, not as the well known built-in directive.

@gkalpak
Copy link
Member

gkalpak commented Sep 30, 2016

Closing as duplicate of #5695.

@gkalpak gkalpak closed this as completed Sep 30, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants