Filter arrays
Angular 2 pipeline for filtering arrays.
npm install ng2-filter-pipe --save
In case you're using systemjs
- see configuration here.
Import pipe and use it in your component
import { Component } from '@angular/core';
import { Ng2FilterPipe } from 'ng2-filter-pipe';
@Component({
selector: 'example-app',
pipes: [Ng2FilterPipe],
template: `
<div>
<input type="text" [(ngModel)]="stringFilter">
<ul>
<li *ngFor="let item of array | filterBy: stringFilter"></li>
<!-- in case you want to show empty message -->
<li *ngIf="(array | filterBy: stringFilter).length === 0">No matching elements</li>
</ul>
</div>
`
})
export class AppComponent {
array: string[] = ['one', 'two', 'three', 'four'];
stringFilter: string = '';
}
Run tests
npm test