Angular 如何将对象值绑定到ngStyle?
我正在尝试使用Angular 如何将对象值绑定到ngStyle?,angular,angular6,Angular,Angular6,我正在尝试使用ngStyle和服务器端返回的对象数组更改按钮的颜色。 从我的服务器,我得到一个对象数组 { id: 1, name: "User 1", designation: "Software Developer", isActive: "Yes", IsActiveStyle: "blue" }, { id: 2, name: "User 2", designation: "Software Developer", isActive: "Yes",
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>
{{item.isActive}
但无法理解,为什么它不改变我按钮的颜色
有更好的方法吗?使用
backgroundColor
而不是backgroundColor
根据@sriharsha_bhat,示例使用烤肉串样式的合成词的工作方式您可以共享html模板编码吗?您可以共享一个工作示例吗?