如何使用代码在ionic中动态改变代码中div的颜色?
最佳答案
如果只是单一样式,可以使用属性绑定(bind)。在您的组件中:
public aColor: string = "#ccc";
然后在 View 中:
<div [style.background-color]="aColor"></div>
请看ngStyle如果您需要动态设置多个样式,请参阅文档以获取更多信息:
<some-element [ngStyle]="{'font-style': styleExp}">...</some-element>
<some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>
<some-element [ngStyle]="objExp">...</some-element>
关于javascript - 通过代码 ionic 改变div的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45115813/