my value in ngIf input has some problem in my code

Viewed 38

I put simple code about my problem to find solutions easier, here is my code :

<div class="loading" *ngIf="!numberFromBack"></div>

so the variable named numberFromBack is a number that server send it to client and it can have values such as : 0 , 1 , 2 , ... and i want to display the loading div when the numberFromBack is null, but i have weird problem , some time the variable has numerical value but *ngIF find it false and with ! before it , changed to true... i need the opposite of this scenario !

1 Answers

I find it, the problem was 0 ! it is a number and the numberFromBack has the value (0), but 0 is a false boolian.so i change code to this :

<div class="loading" *ngIF="!numberFromBack && numberFromBack !==0"></div>

so 0 is false , "0" is true.

Related