ngIf with depending from number binding image in A

2019-09-07 18:48发布

问题:

 <td *ngFor="let user of userService.users | async">
 <div *ngIf="user?.data.apps.details[0].acknowledged as fooIcon">
 <img *ngIf="fooIcon === "1" " src="./app/img/icones_sized/tick.png"/>
 <img *ngIf="fooIcon === "0" " src="nothing_appears"/>
 </div> 

I am trying to display an image if my ".acknowledged" is returning "1" and if it return "0" nothing should be displayed...It works with a string but not with a number..I don't really understand why..

回答1:

You should be using *ngIf...else, as

    <ng-template #loading>
        <img src="./app/img/icones_sized/stable_arrow_small.png"/>
    </ng-template>
    <div *ngIf="user?.data.apps.details[0].acknowledged===1;else loading;">
      <img src="./app/img/icones_sized/tick.png"/>
    </div>