angular - Show an array with ngFor separated by type -
i trying show array using *ngfor can not figure out how show in way want. example, next array:
[bmw, apple, mercedes, lg, banana, iphone] is array of objects use pipe filter array type property , in case have car type, food type , mobile type. array ordered be:
[bmw, mercedes, apple, banana, iphone, lg] well, problem want show in way:
cars: -bmw -mercedes food -apple -banana mobile -iphone -lg using template:
<div *ngfor="let item of items | orderpipe" > <div *nfif="item.type == 'car'> <h3>cars</h3> {{ item.name }} </div> </div> but is:
cars -bmw cars -mercedes food -apple food -banana mobile -iphone mobile -lg
if array ordered type showed, add an*ngif around header:
<div *ngfor="let item of items | orderpipe; let i=index"" > <h3 *ngif="i==0 || items[i-1].type!=items[i].type">{{item.type}}</h3> {{ item.name }} </div> </div> this print header on first iteration,i==0, , each time type changes -- items[i-1].type != items[i].type.
Comments
Post a Comment