You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
using special tailwind class names with recommended [class] bindings #61671
but if we try to use class names like text-primary/80, data-[size='large']:p-8 it gives syntax error.
<!-- Does not work --><div[class.text-primary/80]="isAdmin" [class.data-[size='large']:p-8]="density === 'high'"><!-- Works --><span[class]="{ 'text-green-500/80': true }"> tag </span>
I think style guide should be updated with more examples,
also we could use object like syntax with class binding , but is it recommended?
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
Anything else?
No response
Reacted by nifiro, Hans, schulzi66, Jonas and urugator
Ok, so it seems object syntax is not very useful in such cases.
and if we use like this div class="{{ dense() ? 'any classes you-want' : '' }}" then we cannot add other classes which are common as multiple class attributes will override each other.
as a workaround we can add conditional data attribute and set single class normally with tailwind `data-* as show below:
The binding syntax with complex classnames are a bit hard to read.
Hi, I could agree with this for complex classes like data-[size='large']:p-8 , but as a 1st step consider supporting simpler classes having / character, as classes like text-white/80 , text-xl/relaxed are very common, also it would be great if it could work in same way for SFC too. Thanks.
This is by design, the underlying APIs don't support adding multiple class in a single string (classList.add throws).
Also Angular doesn't want to have to add the cost of handling that implicitly on each and every class.
how does ngClass do it? I would've thought that the same functionality would have ported over.
Should I multiple [class]={'className: store.view()'} to the div or stay with ngClass?
This isn't really an effective solution if an element has many static classes and only a few dynamic classes. In such cases it's still easier to just keep all an element's static classes in class and the few dynamic classes in ngClass.
Aesthetically Ii like the new recommended class bindings approach but until it's a more comprehensive I think I'll still be falling back to good ol' ngClass.
Activity
e-oz commentedon May 24, 2025
You can use
div class="{{ dense() ? 'any classes you-want' : '' }}"e-oz commentedon May 25, 2025
Also about the object usage:
https://stackblitz.com/edit/stackblitz-starters-12ekjcer?file=src%2Fmain.ts
imaksp commentedon May 26, 2025
Ok, so it seems object syntax is not very useful in such cases.
and if we use like this
div class="{{ dense() ? 'any classes you-want' : '' }}"then we cannot add other classes which are common as multiple class attributes will override each other.as a workaround we can add conditional data attribute and set single class normally with tailwind `data-* as show below:
this works perfectly but in this case Angular won't be adding any classes conditionally.
e-oz commentedon May 26, 2025
there is no such limitation
JeanMeche commentedon May 28, 2025
We discuss this a bit with the team.
The binding syntax with complex classnames are a bit hard to read.
For now we would recommend using the binding of objects.
In an external template file
It's a bit more tricky in inline template because this requires additional escaping:
As we have an acceptable alternative today, we'll continue accepting feedback to this issue and we'll think more about it in the future.
imaksp commentedon May 29, 2025
Hi, I could agree with this for complex classes like
data-[size='large']:p-8, but as a 1st step consider supporting simpler classes having/character, as classes liketext-white/80 , text-xl/relaxedare very common, also it would be great if it could work in same way for SFC too. Thanks.anthony-b-dev commentedon Jun 21, 2025
why is there a limitation on class names? Shouldn't this just be a simple string application?
I'm currently trying to conditionally add a whole host of tailwind classes and they're all getting stripped out when trying to use this syntax.
JeanMeche commentedon Jun 21, 2025
This is by design, the underlying APIs don't support adding multiple class in a single string (
classList.addthrows).Also Angular doesn't want to have to add the cost of handling that implicitly on each and every class.
anthony-b-dev commentedon Jun 21, 2025
how does ngClass do it? I would've thought that the same functionality would have ported over.
Should I multiple
[class]={'className: store.view()'}to thedivor stay with ngClass?drakedeatonuk commentedon Jun 21, 2025
This isn't really an effective solution if an element has many static classes and only a few dynamic classes. In such cases it's still easier to just keep all an element's static classes in
classand the few dynamic classes inngClass.Aesthetically Ii like the new recommended class bindings approach but until it's a more comprehensive I think I'll still be falling back to good ol'
ngClass.fix(compiler): allow more characters in square-bracketed attribute names
fix(compiler): allow more characters in square-bracketed attribute na…
angular-automatic-lock-bot commentedon Aug 23, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.