angularangular-pipeangular-dependency-injection

Angular 8 inject pipe into another pipe does not work


After upgrading from Angular 7 to Angular 8 my pipe stopped to work with error:

    TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

      10 | export class APipe implements PipeTransform {
      11 |
    > 12 |   constructor(
         |               ^
      13 |     private readonly bPipe: BPipe,
      14 |     private readonly cPipe: CPipe) {}

or with similar error:

Error: Found non-callable @@iterator

Code of my pipe:

@Pipe({
  name: 'aPipe'
})
export class APipe implements PipeTransform {

  constructor(
    private readonly bPipe: BPipe,
    private readonly cPipe: CPipe) {}

  transform(someValue: any, args?: any): any {
    if (!someValue) {
      return ' — ';
    }

    if (cond1) {
      return this.bPipe.transform(someValue, ...args);
    }
    else {
      return this.cPipe.transform(someValue, ...args);
    }

    return ' — ';
  }

}

Do I have to mark the pipe as @Injectable() explicitly in Angular8 or what is the issue?


Solution

  • Edit

    provide it in your module : Source

    Pipes aren't injectable. They're just usual classes.

    This means that if you want a pipe into another, this will be done with

    const cPipe = new CPipe(...);