Orderby with *ngFor array

为君一笑 提交于 2019-12-01 21:07:09

You should not use ordering pipes.

The Angular team and many experienced Angular developers strongly recommend moving filtering and sorting logic into the component itself

If you want to sort your items by, let's say, name, here it goes :

filterBy(prop: string) {
  return this.composer.arrcompositions.sort((a, b) => a[prop] > b[prop] ? 1 : a[prop] === b[prop] ? 0 : -1);
}

In your HTML :

<mat-list-item *ngFor="let composition of filterBy('name')">
  {{ composition[1] }}
</mat-list-item>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!