Angular

Last Updated: 8/25/2023

ngStyle

  • Use ngStyle to add or remove multiple styles
  • Use property binding syntax and bind ngStyle to an expression
  • An object with 1 or more key value pairs.
  • Each key represents the CSS property
<span [ngStyle]="
{
'bakcgroundColor': canSave ? 'blue': 'gray',
'color': canSave ? 'white': 'black',
}
"></span>
  • If you are dealing with multiple styles the best way is to encapsulate them in CSS class