angular - ngIf check if a variable exists -


right using ngif see if item id 1 , style changes, 2nd statement still runs other objects don't have item id of 1. understand why happening, there way run 2nd statement if item id of 1 doesn't exist in of objects in array? bunch

 <div *ngfor="let item of items">          <div *ngif="(item.details.id == 1)">         somthing      </div>       <div *ngif="(item.details.id != 1)">         somthing      </div>     </div> 

in component code:

// private oneexists: boolean = false; this.oneexists = this.items.filter(item => item.details.id === 1).length > 0; 

in template:

<div *ngfor="let item of items">       <div *ngif="item.details.id === 1">       </div>    <div *ngif="! oneexists">       </div> </div> 

Comments