-
Notifications
You must be signed in to change notification settings - Fork 25.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NgClass and empty string as a class name #4033
Comments
I've renamed this issue as it has nothing to do with NgModel but the crux of the issue is what NgClass does with empty strings. |
@wardbell I wonder how we should fix it. My first reaction is to trim strings representing class names and simply ignore empty (blank) strings. WDYT? |
Trim and ignore extra white space for sure. Empty string should be ignored. It means "no additional class names". I would not mind if this string variant of the NgClass API was removed. The object notion is the most clear and perhaps easier to construct. |
@wardbell right, PR #4173 trims class names. Regarding removal of the string-based form - I don't use it often but it comes handy when you need to calculate class name dynamically (that it, you don't know it up-front). Not super-common, but happens. BTW, in your particular use case the easiest approach would be to go without any directive at all and use the special-cased syntax from the compiler:
|
Yes I have used that and it is worth teaching. Perfect for setting a single class value. Not so great when you have multiple class names to set. So many ways to skin this cat. Are there ever enough? ;-) p.s.: I have no problem calculating a class name dynamically and adding it to the definition object with object indexing: |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Example:
Assume
hero
in this detail changes as a new hero is selected from a parent listtranspiler: show line numbers that have errors #1 First hero displays and the class "selected" is present
Integrate dartanalyzer into build #2 Second hero triggers change in value. Angular fails with exception
DOMException: Failed to execute 'add' on 'DOMTokenList': The token provided must not be empty.(…)
thrown inNgClass.onCheck
in the linethis._applyIterableChanges(changes);
Also fails the same way when
addClass
is:But "works" if it is:
The array-result form is OK
And the object-result form is OK
The text was updated successfully, but these errors were encountered: