Last active
June 4, 2022 13:11
-
-
Save lorenzojkrl/5875801a2eac1481c5af3419bd0f23a8 to your computer and use it in GitHub Desktop.
Angular FilterPipe
This file contains hidden or 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'; | |
import { User } from './model'; | |
@Pipe({ | |
name: 'filter', | |
}) | |
export class FilterPipe implements PipeTransform { | |
transform(value: User[], filterString: string, property: string): User[] { | |
if (value.length === 0 || !filterString) { | |
return value; | |
} | |
let filteredUsers: User[] = []; | |
for (let user of value) { | |
if (user[property].toLowerCase().includes(filterString.toLowerCase())) { | |
filteredUsers.push(user); | |
} | |
} | |
return filteredUsers; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment