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}"
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.
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' }"