Skip to content

Instantly share code, notes, and snippets.

@fireflysemantics
Created May 26, 2022 04:42
Show Gist options
  • Save fireflysemantics/4ed30b502b4218111c06bfc383e5c812 to your computer and use it in GitHub Desktop.
Save fireflysemantics/4ed30b502b4218111c06bfc383e5c812 to your computer and use it in GitHub Desktop.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter',
})
export class FilterPipe implements PipeTransform {
transform(products: any[], query: string): any[] {
if (!products) return [];
if (!query || query.length == 0) return products;
return products.filter(
(p) => p.toLowerCase().indexOf(query.toLowerCase()) != -1
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment