Search code examples
angularpipeangular6angular-pipeangular-library

Angular 6 library pipe


How to add a custom pipe in an Angular 6 library in order for it to be available in my main app ? Currently I'm doing this in: lib.module.ts:

@NgModule({
  declarations: [
    SomePipe
  ],
  exports: [
   SomePipe
]})

in public_api.ts:

export * from './lib/pipes/some.pipe';

in app.module.ts:

import { LibModule } from 'lib';
@NgModule({
  ...
  imports: [
    LibModule
  ]
 ...
})

I'm trying to use the pipe {{ 'something' | some}} but transform method of SomePipe is not called.


Solution

  • The custom pipe was added correctly, and was working in my application. There was another bug that I did not manage to see, regarding a service (imported incorrectly from the library) that my @Pipe was using inside the transform() method. Therefore, transform() always appeared to return nothing, because it was relying on that service.