I have custom Pipe. That I imported to ngModule of component.
declarations: [SearchFilterPipe]
In this component I try to use this pipe as:
<div *ngFor="let item of studyPlan | searchfilter : value">
It gives me an error: The pipe 'searchfilter' could not be found
. Also variable value
is not available in this line.
Pipe is:
import { Injectable, Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'searchfilter'
})
@Injectable()
export class SearchFilterPipe implements PipeTransform {
transform(items: any[], field: string, value: string): any[] {
if (!items) { return []; }
return items.filter(it => it[field] === value);
}
}
Module of component is:
@NgModule({
...
declarations: [SearchFilterPipe],
exports: [SearchFilterPipe]
})
Either
@Pipe({name: 'searchfilter'})
decorator doesn't exactly matchdeclarations: [SearchFilterPipe]
is not in the same module as the component containing <div *ngFor="let item of studyPlan | searchfilter : value">
imports: [TheModuleContainingThePipe]
is missing if the pipe and the component that uses it are part of different modules.exports: [SearchFilterPipe]
is missing in the @NgModule()
that contains the pipe.Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments