angular - 在组件中检测到角度循环依赖
问题描述
我有 2 个组件,每个组件都需要导入其他组件。导入时会在终端“检测到循环依赖”中发出警告。
我的组件代码如下:
组件 1
import { ReservationDateInfoComponent } from 'app/modules/reservation-date-info.component';
export class RateInfoComponent implements OnInit {
constructor(private dialog: MatDialog){}
openDateInfo(){
this.dialog.open(ReservationDateInfoComponent, { width: '1000px'});
}
}
组件 2
import { RateInfoComponent } from '../../../core/shared/components/rate-info/rate-info.component';
export class ReservationDateInfoComponent implements OnInit {
constructor(private dialog: MatDialog){}
openRateInfo(){
this.dialog.open(RateInfoComponent, { width: '1000px'});
}
}
解决方案
循环依赖显然出现了,因为在ReservationDateInfoComponent中您导入了RateInfoComponent,即再次导入了ReservationDateInfoComponent。
以下描述了您的圈子:
RateInfoComponent -> ReservationDateInfoComponent -> RateInfoComponent ....
可能的解决方案
并且附加组件可以导入所有需要的模态并连续显示它们。听起来您还需要在模态组件之间传输数据。这可以通过使用Observables来实现。这样,您的第三个组件应该订阅每个模式以获取其数据。
推荐阅读
- php - 致命错误:未捕获的 InvalidArgumentException:
- c# - 在使用 SmartAssembly 合并之前和之后是否需要对合并的 C# 程序集进行单元测试?
- python-3.x - 如何从包含多个客户条目的表中找到每个唯一客户最常出现的类别?
- sql - Msg 8152, Level 16, State 14, Line 1 字符串或二进制数据将被截断
- twitter-bootstrap-3 - bootstrap3.7 modal 调整宽度到内容
- python - 如何测试 stanfordnlp 是否在 gpu 上运行?
- python - 使用函数运行游戏
- arrays - Solr Facet 在多个术语中拆分字符串。如何包含空格?
- php - 使用 Laravel 资源将字段数据格式化为字典
- sql - SQL Server 中带有 OUTPUT 子句的 UPDATE 查询