Angular 5+ pipeline for filtering arrays
npm install @guramrit/ngx-filter-pipe> Filter arrays
Angular 5+ pipeline for filtering arrays.

https://vadimdez.github.io/ngx-filter-pipe/
or see demo code
https://stackblitz.com/edit/ngx-filter-pipe
##### In HTML template
```
{{ collection | filterBy: searchTerm }}
| Param | Type | Details |
| --- | --- | --- |
| collection | array | The collection to filter |string
| searchTerm | or number or object or array or function | Predicate used to filter items from collection |
``
npm install ngx-filter-pipe --save1.0.2
For Angular lower than 5 use version
In case you're using `SystemJS` - see configuration here.
Import FilterPipeModule to your module
`ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app';
import { FilterPipeModule } from 'ngx-filter-pipe';
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [BrowserModule, FormsModule, FilterPipeModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
`
And use pipe in your component
`ts
import { Component } from '@angular/core';
@Component({
selector: 'example-app',
template:
})
export class AppComponent {
users: any[] = [{ name: 'John' }, { name: 'Jane' }, { name: 'Mario' }];
userFilter: any = { name: '' };
}
`$3
Use $or to filter by more then one values.$or expects an Array.In your component:
`ts
// your array
const languages = ['English', 'German', 'Russian', 'Italian', 'Ukrainian'];
// your $or filter
const filter = { $or: ['German', 'English'] };
`In your template:
`html
{{ language }}
`Result will be:
`html
English
German
`#### $or example with nessted values
In your component:
`ts
// your array
const languages = [
{ language: 'English' },
{ language: 'German' },
{ language: 'Italian' }
];// your $or filter
const filter = {
language: {
$or: ['Italian', 'English']
}
};
`In your template:
`html
{{ object.language }}
`Result:
`html
English
Italian
`#### $or example with multiple predicates
`
const objects = [
{ name: 'John' },
{ firstName: 'John' }
]const filter = { $or: [{ name: 'John' }, { firstName: 'John' }] }
`
In your template:
`html
{{ object | json }}
`Result:
`html
{ name: 'John' }
{ firstName: 'John' }
`$3
Inject
FilterPipe into your component and use it:`ts
class AppComponent {
objects = [
{ name: 'John' },
{ name: 'Nick' },
{ name: 'Jane' }
];
constructor(private filter: FilterPipe) {
let result = this.filter.transform(this.objects, { name: 'J' });
console.log(result); // [{ name: 'John' }, { name: 'Jane' }]
}
}
`Test
Run tests
`
npm test
``