Angular filter for last element -
how can write filter , returns last element of list / how can write filter returns last element.
background: i'm having list of items, last item should editable. therefor need filter it.
you use pipe
filter array
pipe
@pipe({name: 'lastitem'}) export class lastitempipe implements pipetransform { transform(items: any[], exclusive: boolean): { if (exclusive) { return items.slice(0, items.length - 1); } return [items[items.length - 1]]; } }
template
<h2>list without</h2> <div *ngfor="let item of items | lastitem:true">{{item}}</div> <h2>list with</h2> <div *ngfor="let item of items | lastitem:false">{{item}}</div>
Comments
Post a Comment