ngStyle
添加变量到ngStyle中
<p [ngStyle]="{'width.px': pWidth}"></p>
根据变量添加不同属性
<p [ngStyle]="{'display': showP ? 'block': 'none'}"></p>
花式添加style
ts中直接在组件顶层dom添加style
@Component({
selector : 'p-sample',
host : {
'[style.color]' : `'red'`
}
})
html中添加style
<p [style.color]="'red'"></p>
ngStyle
添加变量到ngStyle中
根据变量添加不同属性
花式添加style
ts中直接在组件顶层dom添加style
html中添加style