Skip to content

Instantly share code, notes, and snippets.

@riapacheco
Created July 20, 2022 18:12
Show Gist options
  • Save riapacheco/395548878bff85e2d638868a26ecfc1b to your computer and use it in GitHub Desktop.
Save riapacheco/395548878bff85e2d638868a26ecfc1b to your computer and use it in GitHub Desktop.
Angular pipe to filter all values in an array of objects [no key/field name required]
export class FilterAllPipe implements PipeTransform {
transform(value: any, searchText: any): any {
if (!searchText) { return value; }
return value.filter((data: any) => this.matchValue(data, searchText));
}
matchValue(data: any, value: any) {
return Object.keys(data).map((key) => {
return new RegExp(value, 'gi').test(data[key]);
}).some(result => result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment