ngClass测试:
HTML文件:
<div [ngClass]="{red: flag}"
[ngClass]="{blue: !flag}"> ngClass 测试</div>
在ts文件中定义flag:
public flag:boolen = true
在sass文件中
.red:
color: red
.blue:
color: blue
解析: 表示在HTML文件中用flag的true和false值来改变该文字的颜色
flag在ts文件中定义值。
ngStyle测试:
html文件:
当值是固定的时:对象里面需要带双引号
<div [ngStyle]="{'background-color': 'red'}"> ngStyle 测试</div>
当值不是固定:对象里面给的时一个参数,不带引号
html:
<div [ngStyle]="{'background-color': attr}"> ngStyle 测试</div>
ts:
public attr = 'red';