/ng2-filter-pipe

Angular 2 pipeline for filtering arrays.

Primary LanguageTypeScriptMIT LicenseMIT

Angular2 Filter Pipe

npm version

Filter arrays

Angular 2 pipeline for filtering arrays.

Install

npm install ng2-filter-pipe --save

Usage

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 = '';
}

Test

Run tests

npm test

License

MIT © Vadym Yatsyuk