我正在尝试使用ngStyle
更改按钮的颜色,并从我的服务器端返回对象数组。
从我的服务器,我得到一个对象数组
{
id: 1,
name: "User 1",
designation: "Software Developer",
isActive: "Yes",
IsActiveStyle: "blue"
},
{
id: 2,
name: "User 2",
designation: "Software Developer",
isActive: "Yes",
IsActiveStyle: "blue"
},
{
id: 3,
name: "User 3",
designation: "Software Tester",
isActive: "No",
IsActiveStyle: "red"
},
{
id: 4,
name: "User 4",
designation: "Tester",
isActive: "Yes",
IsActiveStyle: "blue"
}
我正在尝试使用以下代码将IsActiveStyle
绑定到ngStyle
<button [ngStyle]="{'background-color':item.IsActiveStyle}">{{item.isActive}}</button>
但无法理解,为什么它没有改变我按钮的颜色。
有没有更好的方法呢?