Ionic change background color of div by code

跟風遠走 提交于 2020-05-29 07:34:08

问题


How to change the color of a div in code dynamically in ionic by using code?


回答1:


If it's just a single style, you can use property binding for this. In your component:

public aColor: string = "#ccc";

And then in the view:

<div [style.background-color]="aColor"></div>

Please take a look at the ngStyle docs for more info if you need to set more than one style dynamically:

<some-element [ngStyle]="{'font-style': styleExp}">...</some-element>    
<some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>    
<some-element [ngStyle]="objExp">...</some-element>


来源:https://stackoverflow.com/questions/45115813/ionic-change-background-color-of-div-by-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!