UNPKG

fabric8-stack-analysis

Version:
32 lines (28 loc) 872 B
import { Pipe, PipeTransform, Injectable } from '@angular/core'; @Pipe({ name: 'filter' }) /* * A generic filter that gives you the filtered output * on passing the key and value to be filtered upon * Takes a key - fielname, and a value - fieldValue * Returns the filtered Array of objects or anything * * Name: 'filter' * Usage: * * Use as a pipe, * In a loop: * *ngFor="let something of (manythings | filter : fieldNameAsVariable {or 'simply name'} : fieldValueAsVariable {or 'simply value'})" */ @Injectable() export class TableFilter implements PipeTransform { public transform(items: Array<any>, field: string, value: string): Array<any> { if (!items) { return []; } if (!field || !value) { return items; } return items.filter(item => item[field].includes(value)); } }