Created
May 4, 2018 06:53
-
-
Save hassansw/28a3aa7729de1f4c27cf2b760fc55131 to your computer and use it in GitHub Desktop.
Angular Filter Pipe
This file contains 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 characters
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'filter' | |
}) | |
export class FilterPipe implements PipeTransform { | |
transform(items: any[], searchText: string): any[] { | |
if (!items) return []; | |
if (!searchText) return items; | |
searchText = searchText.toLowerCase(); | |
return items.filter(it => { | |
return it.toLowerCase().includes(searchText); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment