ngClass和[ngClass]在angular6中有什么区别

时间:2018-11-15 12:48:29

标签: javascript typescript angular6

有人可以指定ngclass =“”和[ngClass] =“ {'class name'}”之间的区别。

1 个答案:

答案 0 :(得分:0)

ngClass仅将值作为字符串获取,但是如果您使用[ngClass],它将尝试将值作为任何变量获取。您还可以设置和反对设置条件下的类。像:{active:valueOne===valueTwo}

<some-element [ngClass]="'first second'">...</some-element>

<some-element [ngClass]="['first', 'second']">...</some-element>

<some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>

<some-element [ngClass]="stringExp|arrayExp|objExp">...</some-element>

<some-element [ngClass]="{'class1 class2 class3' : true}">...</some-element>

此处有更多详细信息:https://angular.io/api/common/NgClass