Created
March 21, 2019 23:08
-
-
Save subratastack/e7b8c9d7eb030af9f3b2a45431b87fb4 to your computer and use it in GitHub Desktop.
Angular 7 Pipes
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: '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