角度8将管道注入另一个管道不起作用

时间:2019-10-02 06:45:37

标签: angular angular-pipe angular-dependency-injection

从Angular 7升级到Angular 8后,我的 pipe 停止工作并出现错误:

    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) {}

或有类似错误:

Error: Found non-callable @@iterator

我的管道代码:

@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 ' — ';
  }

}

我必须在Angular8中将管道明确标记为@Injectable()还是问题?

1 个答案:

答案 0 :(得分:2)

编辑

在您的模块中提供它:Source

管道不可注射。他们只是普通班。

这意味着,如果您希望将管道插入另一个管道,则可以使用

const cPipe = new CPipe(...);