Angular:带* ngClass的条件类
我的Angular代码有什么问题?我正进入(状态:
Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass ...
<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>
回答:
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'"
以上是 Angular:带* ngClass的条件类 的全部内容, 来源链接: utcz.com/qa/423724.html