dynamic class binding not working in angular 9


I need to display dynamic color for a div based on some condition. I am getting console error.

I have tried

<div [ngClass]="{'clr-{{students.rollNo+1}}': students.active}"></div>

students is my array, i have a class called .clr-5, clr-6 etc… in css


try this:

<div [ngClass]="[ students.active ? 'clr-'+students.rollNo+1 : '']"></div>

class bindings are updated in Angular 9. Read more about it here

Answered By – Noor Ul Ain

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published