I'm filtering the items using the pipe to filter
My Input filed is in the search.html file and Itemlist in the List.html file
Change in the model is not triggering the pipe transform.
Please help. Below is the code snippet.
Search.html
<input placeholder="keyword..." [(ngModel)]="search"/>
List.html
<div *ngFor="let item of items | searchPipe:'name':search ">
{{item.name}}
</div>
Search.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name : 'searchPipe',
})
export class SearchPipe implements PipeTransform {
public transform(value, key: string, term: string) {
return value.filter((item) => {
if (item.hasOwnProperty(key)) {
if (term) {
let regExp = new RegExp('\\b' + term, 'gi');
return regExp.test(item[key]);
} else {
return true;
}
} else {
return false;
}
});
}
}