How to apply filters to *ngFor?

前端 未结 23 1593
無奈伤痛
無奈伤痛 2020-11-22 03:44

Apparently, Angular 2 will use pipes instead of filters as in Angular1 in conjunction with ng-for to filter results, although the implementation still seems to be vague, wit

23条回答
  •  天涯浪人
    2020-11-22 04:10

    Here's an example that I created a while back, and blogged about, that includes a working plunk. It provides a filter pipe that can filter any list of objects. You basically just specify the property and value {key:value} within your ngFor specification.

    It's not a lot different from @NateMay's response, except that I explain it in relatively verbose detail.

    In my case, I filtered an unordered list on some text (filterText) the user entered against the "label" property of the objects in my array with this sort of mark-up:

    • {{ item.label }}

    https://long2know.com/2016/11/angular2-filter-pipes/

提交回复
热议问题