Angular:通过*ngClass进行条件类的设置

32 浏览
0 Comments

Angular:通过*ngClass进行条件类的设置

我的Angular代码有什么问题?我遇到了以下错误:

在BrowserDomAdapter.removeClass中,无法读取未定义的属性\'remove\'

    1. Step1

 

    1. Step2

 

    1. Step3

 

 

admin 更改状态以发布 2023年5月20日
0
0 Comments

[ngClass]=... 而不是 *ngClass

* 只用于结构指令的简写语法,例如可以使用

{{item}}

而不是较长的等效版本


另请参见https://angular.io/docs/ts/latest/api/common/index/NgClass-directive.html

...
...
...
...
...

另请参见https://angular.io/docs/ts/latest/guide/template-syntax.html


The class binding is special

This one is not so special


Bad curly

0
0 Comments

Angular 版本 2+ 提供了多种条件添加类的方式:

类型 1

    [class.my_class] = "step === 'step1'"

类型 2

    [ngClass]="{'my_class': step === 'step1'}"

还有多个选项:

    [ngClass]="{'my_class': step === 'step1', 'my_class2' : step === 'step2' }"

类型 3

    [ngClass]="{1 : 'my_class1', 2 : 'my_class2', 3 : 'my_class4'}[step]"

类型 4

    [ngClass]="step == 'step1' ? 'my_class1' : 'my_class2'"

你可以在文档页面上找到这些示例。

0