1 2 3 4 5 6 7
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'filter' }) export class FilterPipe implements PipeTransform {
8 9
transform(value: any, filterString: string, propName: string): any { if (value.length === 0) {
10
return value;
11 12 13
} const resultArray = [];
14
for (const item of value) {
15 16
if (item[propName] === filterString) { resultArray.push(item);
17
}
18
19 20
} return resultArray;
21
22 23