Skip to content

Instantly share code, notes, and snippets.

@hassansw
Created May 4, 2018 06:53
Show Gist options
  • Save hassansw/28a3aa7729de1f4c27cf2b760fc55131 to your computer and use it in GitHub Desktop.
Save hassansw/28a3aa7729de1f4c27cf2b760fc55131 to your computer and use it in GitHub Desktop.
Angular Filter Pipe
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