1

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?

Felix
  • 3,999
  • 3
  • 42
  • 66

1 Answers1

3

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(...);

  • 3
    This is wrong. You can inject a pipe in component, services, etc. Here's a working stackblitz project: https://stackblitz.com/edit/angular-tdvz6q – Harun Yilmaz Oct 02 '19 at 06:54
  • 5
    Indeed, `If you choose to inject your pipe into a class, you must provide it in the providers array of your NgModule.`. Didn't know that ! ([source](https://angular.io/guide/pipes#the-pipetransform-interface)) –  Oct 02 '19 at 07:06