Search code examples
angularlogical-or

how to use 'or' statement in ngif in angular4?


I am using the angular4, my code below is trying to display the information basesd on the state variable.

<div *ngIf="state!='open' || state!='canceled'"> something </div>

I am using '||' to represent the 'or' statement.

now the state variable = 'canceled', usually it should not display 'something', however in the test 'something' text is still there.

if i used the statement below, it works that the 'something' text disappear.

<div *ngIf="state!='canceled'"> something </div>

if i used the statement, it still doesn't work so it doesn't seem to be the ordering issue.

<div *ngIf="state!='canceled'"|| state!='open'  > something </div>

anything wrong?


Solution

  • You have a logic error. if the variable is equal to cancel also is different to open, so the result of the conditional will be true.