Angular: conditional class with *ngClass

后端 未结 19 1962
醉话见心
醉话见心 2020-11-22 05:21

What is wrong with my Angular code? I am getting:

Cannot read property \'remove\' of undefined at BrowserDomAdapter.removeClass ...

19条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 05:42

    to extend MostafaMashayekhi his answer for option two> you can also chain multiple options with a ','

    [ngClass]="{'my-class': step=='step1', 'my-class2':step=='step2' }"
    

    Also *ngIf can be used in some of these situations usually combined with a *ngFor

    class="mats p" *ngIf="mat=='painted'"
    

提交回复
热议问题