angular - 使用@Inject(forwardRef(()) 将数据从管道发送到组件
问题描述
我正在尝试将过滤后的数组从我的管道发送到我的组件,使用@Inject(forwardRef(())
如下:
过滤器.pipe.ts
constructor(@Inject(forwardRef(() => OpenItemsComponent)) private ded_open: OpenItemsComponent) {}
transform(items: any[], field: string, value: string[]): any[] {
...
this.ded_open.filteredData(this.newArray)
...
}
应用程序.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(Platform:core)[FilterPipe -> ClosedItemsComponent]:NullInjectorError:没有ClosedItemsComponent的提供者!
我不能在管道构造函数中注入更多组件?我该如何解决这个问题?感谢您的时间!
(PS - 我知道使用管道不好,但这只是一个演示,不是最终版本)
解决方案
推荐阅读
- r - 动作按钮在闪亮的应用程序中第二次按下后起作用
- javascript - RobotFramework - 执行 Javascript
- bcp - BCP 在命令提示符下工作,但在 SSMS 中不工作
- vue.js - nuxt 中的动态重写 url
- email - 如何为 mjml 中的列设置固定宽度?
- python - 生成 3 个随机列表并使用它们的元素总和创建另一个
- r - 基本图 - 如何在 X 轴上使用文本标签?
- html - 如何在转换为pdf的ejs模板中添加图像
- spring - 使用多个配置文件的 Spring Boot 注入问题
- python - 根据名称正则表达式python将字符串拆分为列表