Angular 2,..,7 provides several ways to add classes conditionally:
(Angular 2,..,7提供了几种有条件地添加类的方法:)
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'"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…