Parameter-based dynamic class display
P粉311423594
P粉311423594 2023-09-14 12:25:45
0
1
480

I have some CSS classes that can have multiple names, how do I pass these names to ngClass?

The following is an example that doesn't work. How do I pass itemName to ngClass?

<div [ngClass]="isItem ? 'item {{itemName}}' : 'noItem {{itemName}}'">
</div>

P粉311423594
P粉311423594

reply all(1)
P粉627027031

Template interpolation is not possible inside the [ngClass] directive, just remove the brackets and concatenate the variable with the string.

<div [ngClass]="isItem ? 'item '+itemName : 'noItem'+itemName"></div>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template