如何通过角度界限值设置背景色 [英] How to set background-color by angular bound value

查看:93
本文介绍了如何通过角度界限值设置背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的角度应用程序(版本4.2.6),用于显示图块.我想通过绑定到图块对象的值来设置这些图块的背景色.设置图块的内容按预期工作时,设置颜色失败:

I have a simple angular app (version 4.2.6) that displays tiles. I want to set the background color of those tiles by a value bound to tile object. While setting the content of the tile works as expected, setting the color fails:

<div *ngFor="let tile of tiles" class="col-md-3 col-sm-6 col-xs-12" >
    <div style="border-style: solid;width: 150px;height: 150px;background-color:{{tile.color}};" class="tile">{{tile.name}}</div>
</div>

如何通过绑定值 tile.color (它包含颜色作为十六进制字符串)来设置背景颜色?

How to set background-color by bound value tile.color (it contains color as hex string )?

推荐答案

您可以使用 [style.backgroundColor] ="tile.color"

 <div [style.backgroundColor]="tile.color" ...></div>

这篇关于如何通过角度界限值设置背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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