crear pipe para filtrado

This commit is contained in:
Eduardo Quiros 2021-07-10 19:34:08 -06:00
parent 572ba5362d
commit 4a0e6a2c81
No known key found for this signature in database
GPG Key ID: B77F36C3F12720B4
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
import { Pipe, PipeTransform, Injectable } from '@angular/core';
@Pipe({
name: 'filter',
})
@Injectable()
export class FilterPipe implements PipeTransform {
transform(items: any[], field: string, value: string): any[] {
if (!items) {
return [];
}
if (!field || !value) {
return items;
}
return items.filter(singleItem => singleItem[field].toLowerCase().includes(value.toLowerCase()));
}
}