我正在尝试使用@Inject(forwardRef(())
这样将过滤后的数组从管道发送到组件:
filter.pipe.ts
constructor(@Inject(forwardRef(() => OpenItemsComponent)) private ded_open: OpenItemsComponent) {}
transform(items: any[], field: string, value: string[]): any[] {
...
this.ded_open.filteredData(this.newArray)
...
}
app.ts
...
filteredData(val) {
this.currentFilter = val.slice()
console.log(this.currentFilter) // in currentFilter I will have the filtered array
...
}
我要注入的组件更多,因为我在4个组件中使用了此管道。我尝试过这样的事情:
constructor(
@Inject(forwardRef(() => OpenItemsComponent)) private ded_open: OpenItemsComponent,
@Inject(forwardRef(() => ClosedItemsComponent)) private ded_closed: ClosedItemsComponent,
@Inject(forwardRef(() => TrdIComponent)) private trade_open: TradeInvoicesComponent,
@Inject(forwardRef(() => TrdIClosedComponent)) private trade_closed: TradeInvoicesClosedComponent) {
}
但我明白了
错误错误:未捕获(承诺):错误:StaticInjectorError(AppModule)[FilterPipe-> ClosedItemsComponent]: StaticInjectorError(平台:核心)[FilterPipe-> ClosedItemsComponent]: NullInjectorError:ClosedItemsComponent没有提供程序!
我不能在管道构造函数中注入更多组件吗?我该如何解决?谢谢您的时间!
(PS-我知道使用管道是不好的,但这只是用于演示,而不是最终版本)