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> 

live plunker example


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -