I've created this pipe
import {Pipe, PipeTransform} from '@angular/core'
@Pipe({
name: 'search'
})
export class SearchPipe implements PipeTransform {
public transform(value, keys: string, term: string) {
if (!term) return value;
return (value || []).filter((item) => keys.split(',').some(key => item.hasOwnProperty(key) && new RegExp(term, 'gi').test(item[key])));
}
}
and put it inside search.pipe.ts
How do I import it inside my main component class and how do I register it?
I've checked this tutorial and they show an example of using it inside the component but they do not show how they import and register it.
I've tried this inside my main component
import { SearchPipe } from './search.pipe.ts'
@NgModule({
declarations: [ SearchPipe ]
})
and then in html file of the same component I tried this:
<ul *ngFor="let item of costCenters | search:'orgnumber,orgname':tempNode.cost_center">
<li>{{item.orgname}}</li>
</ul>
It produces this error:
The pipe 'search' could not be found ("gIf="showCostCenterDropDown" class="cost-center-dropdown">
<ul *ngFor="let [ERROR ->]item of costCenters | search:'orgnumber,orgname':tempNode.cost_center">
"): ng:///AppModule/TripTagsComponent.html@46:40