Skip to content

Instantly share code, notes, and snippets.

@subratastack
Created March 21, 2019 23:08
Show Gist options
  • Save subratastack/e7b8c9d7eb030af9f3b2a45431b87fb4 to your computer and use it in GitHub Desktop.
Save subratastack/e7b8c9d7eb030af9f3b2a45431b87fb4 to your computer and use it in GitHub Desktop.
Angular 7 Pipes
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'userSearch'
})
export class SearchPipe {
transform(data: any[], args: string): any[] {
if (args === '') {
return data;
} else {
return data.filter(data =>
data.first_name.toLowerCase().indexOf(args.toLowerCase()) !== -1 ||
data.last_name.toLowerCase().indexOf(args.toLowerCase()) !== -1 ||
data.country.toLowerCase().indexOf(args.toLowerCase()) !== -1 ||
data.gender.toLowerCase().indexOf(args.toLowerCase()) !== -1 ||
data.age.toString().toLowerCase().indexOf(args.toLowerCase()) !== -1
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment