Search code examples
angularpropertiesng-style

NgStyle setting two properties Angular


I'm trying to set two properties based on the condition. I have this code:

<tr [ngStyle]="user.current ? {'background-color' : '#002147', 'color': '#fff' } 
: {'background-color': 'transparent', 'color': black}" *ngFor="let user of users; index as i">
...

My problem is that it only sets the first property (background-color), nothing happens with the text color. Can you please help me? Thank you very much! Have a nice day!


Solution

  • You should check and try other things, your code looks right.

    • Check if there is already a color set on your "tr" element with !important annotation
    • Try to switch color and background color to see what happen
    • Your forgot single quote on "color: black" properties

    I hope this can help you