离子通过代码更改div的背景颜色 [英] Ionic change background color of div by code

查看:96
本文介绍了离子通过代码更改div的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过使用代码在ionic中动态更改代码中div的颜色?

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

推荐答案

如果只是单一样式,则可以使用属性绑定.在您的组件中:

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

public aColor: string = "#ccc";

然后在视图中:

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

如果需要设置更多信息,请查看 ngStyle 文档以获取更多信息.动态地一种样式:

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>

这篇关于离子通过代码更改div的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆