Angular: conditional class with *ngClass

后端 未结 19 2227
醉话见心
醉话见心 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:31

    Angular version 2,...,9 provides several ways to add classes conditionally:

    type one

    [class.my-class]="step === 'step1'"
    

    type two

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

    and multiple option:

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

    type three

    [ngClass]="{1:'my-class1',2:'my-class2',3:'my-class4'}[step]"
    

    type four

    [ngClass]="(step=='step1')?'my-class1':'my-class2'"
    

提交回复
热议问题