I have a pipe
@Pipe({name: 'keys'})
export class KeysPipe implements PipeTransform {
transform(value, args:string[]) : any {
.....
return keys;
}
}
I have two modules in which I need to use this. If I do something like this in both the modules, I get an error saying that "two modules declare KeysPipe"
Module1, Module2:
declarations: [KeysPipe],
I then tried exporting KeysPipe through it's own module so that I can import it in to the two modules in which I need to use it
@NgModule({
declarations: [ KeysPipe],
})
export class KeysPipeModule {
}
Now I'm importing the KeysPipeModule in the two modules I need to use KeysPipe
Module1, Module2:
imports: [KeysPipeModule],
But now I get a different template error saying that the pipe isn't found "The pipe 'keys' could not be found ("v *ngIf="docalc">"
Angular Pipes Multiple custom pipesIt is possible to bundle all frequently used pipes in one Module and import that new module in any component needs the pipes.
Yes, you can define multiple modules in angularJS as given below. The modularization in AngularJS helps us to keep the code clarity and easy to understand, as we can combine multiple modules to generate the application.
You're on the right track the only thing your code is missing is the export in the KeysPipeModule
. This is what it should look like:
@NgModule({
declarations: [ KeysPipe],
exports: [KeysPipe]
})
export class KeysPipeModule {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With