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
  • 10,276
  • 14
  • 44
  • 77

3 Answers3

0

It is possible according to official reference.

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
  • 145
  • 1
  • 9
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
  • 831
  • 5
  • 15