温馨提示:本文翻译自stackoverflow.com,查看原文请点击:javascript - Angular: conditional class with *ngClass

javascript - Angular:带* ngClass的条件类提示错误:Cannot read property 'remove' of undefined at BrowserDomAdapter.removeCla

发布于 2020-03-31 23:15:34

我的Angular代码有什么问题?错误代码

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

的HTML

<ol class="breadcrumb"> <li *ngClass="{active: step==='step1'}" (click)="step='step1; '">Step1</li> <li *ngClass="{active: step==='step2'}"  (click)="step='step2'">Step2</li> <li *ngClass="{active: step==='step3'}" (click)="step='step3'">Step3</li> </ol> 

查看更多

提问者
daniel
被浏览
14
675 2020-02-19 13:13

Angular版本2,...,9提供了几种有条件地添加类的方法:

第一类

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

第二类

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

和多个选项:

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

第三类

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

四类

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

发布
问题

分享
好友

手机
浏览

扫码手机浏览