0

I am trying to change the color of a button using ngStyle and the array of object return from my server side. From my server, I am getting an array of objects

{
  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"
}

I am trying to bind, my IsActiveStyle to ngStyle with the following code

<button [ngStyle]="{'background-color':item.IsActiveStyle}">{{item.isActive}}</button>

but unable to understand, why it is not changing the color of my button.

is there any better way to do this?

DevProf
  • 794
  • 2
  • 9
  • 20

0 Answers0