Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何将对象值绑定到ngStyle?_Angular_Angular6 - Fatal编程技术网

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模板编码吗?您可以共享一个工作示例吗?