Angular 2 - ngFor index after a pipe

前端 未结 2 1236
旧巷少年郎
旧巷少年郎 2020-12-10 15:54

In Angular 2 when using ngFor how would I get the original index for an object within an array after it has been passed through a pipe?

For example if I have an arra

2条回答
  •  眼角桃花
    2020-12-10 16:45

    If i understood you correctly you want index of original list, in that case you can use that filtered object to find out origin index from original list.

    {{getIndex(iteml)}} - {{item.id}}

    and then define geIndex method in you component which can return Index from original list which is not been filtered.

    getIndex(item: Item) {
        return this.list.indexOf(this.list.filter((i, index) => item.id == i.id)[0])
    }
    

提交回复
热议问题