0

How can I use operators with ngClass ? For example, I would like to apply a class only if someValue equals otherValue

[ngClass]="{active: someValue === otherValue}"
Lev
  • 13,856
  • 14
  • 52
  • 84

3 Answers3

0

It is possible according to official reference.

André Luiz Carletti
  • 1,079
  • 2
  • 9
  • 10
0

You can use any operators if in the end the expression will return true or false.

[ngClass]="{online: serverStatus === 'online'}"

This is my example - the expression returns true when serverStatus is online, and then class .online is applied.

Bartosz Gajda
  • 984
  • 6
  • 14
0

Pls try the below code. The class active will get triggered when the condition someValue = otherValue.

[ngClass]="{'active': someValue == othervalue}"

or

[ngClass]="{'active': someValue === othervalue}"

If you want to add a class by checking with any specific value such as 0, pls try

[ngClass]="{'active': someValue == '0' }"
Veena K. Suresh
  • 942
  • 5
  • 16