-
-
Save smorcuend/2e8fbf0b278793b064652d26f85be5f9 to your computer and use it in GitHub Desktop.
Revisions
-
ranakrunal9 created this gist
Nov 18, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ <!-- Pipe Usage in HTML --> <input placeholder="keyword..." [(ngModel)]="search"/> <div *ngFor="let item of items | searchPipe:'name':search "> {{item.name}} </div> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ 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; } }); } }