can you please tell me how to use ng2-filter-pipe insdie code in class
salluu opened this issue · 2 comments
salluu commented
can you please tell me how to use ng2-filter-pipe insdie code in class not inside template thanks
like in angular 1 it was something like this var filtered = $filter('filter')(array, stringtosearch)
VadimDez commented
The same way like any other pipe.
Here is how:
Firstly, import Ng2FilterPipe
import { Ng2FilterPipe } from 'ng2-filter-pipe';
Add Ng2FilterPipe
to providers
in your module
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [Ng2FilterPipe],
bootstrap: [AppComponent]
})
export class AppModule { }
Use Ng2FilterPipe in ts:
import { Component } from '@angular/core';
import { Ng2FilterPipe } from 'ng2-filter-pipe';
@Component({
selector: 'app-component',
template: '...'
})
export class AppComponent {
collection: any[] = [
{
name: 'John'
},{
name: 'Mary'
}
];
constructor(private filterPipe: Ng2FilterPipe) {
console.log(this.filterPipe.transform(this.collection, { name: 'Mary' }));
}
}
salluu commented
many thanks for quick response