Angular Conditional Classes error “Cannot read property ‘remove’ of undefined at BrowserDomAdapter.removeClass”

There are several ways to conditionally add or change classes in Angular 2+ versions.

1st case

[ngClass]="{'your-class-name': yourCondition }"
[ngClass]="{'myClass': task === 1 }"

2nd case

[class.myClass]="task === 1"

3rd case

[ngClass]="{'myClass': task === 1, 'myClass2':task === 2 }"

4th case


5th case


Leave a Reply

(*) Required, Your email will not be published