angular - Angular 6 组件中的循环依赖
问题描述
我有三个角材质对话框,单击后退按钮时它应该打开上一个对话框,但是当我尝试这样做时,我遇到了循环依赖问题
WARNING in Circular dependency detected:
src\app\shared\dialog\continue-popup\continue-popup.component.ts -> src\app\shared\dialog\show-cart\show-cart.component.ts -> src\app\shared\dialog\checkout-popup\checkout-popup.component.ts ->
src\app\shared\dialog\continue-popup\continue-popup.component.ts
WARNING in Circular dependency detected:
src\app\shared\dialog\show-cart\show-cart.component.ts -> src\app\shared\dialog\checkout-popup\checkout-popup.component.ts -> src\app\shared\dialog\continue-popup\continue-popup.component.ts ->
src\app\shared\dialog\show-cart\show-cart.component.ts
上一个弹出窗口中的此代码导致问题
gotoPaymentInfo() {
this.dialogRef.close();
this.dialogService.openDialog(CheckoutPopupComponent, this.countryList);
}
如果我尝试在关闭弹出窗口时尝试使用导致突然行为的主题,我不确定如何修复它。您能否建议解决错误的正确方法是什么。
在单击 ok 的结帐组件中,我调用 this.dialogServie.openDialog(ContinuePopupComponent) 而在后退按钮单击 ContinuePopupComponent 我调用 this.dialogServie.openDialog(CheckoutPopupComponent) 导致问题
解决方案
我找到了问题的根本原因,这是因为我试图从对话框 b 打开对话框 a,然后再次单击从对话框 b 到 a 的后退按钮。我通过单击后退按钮使用行为主题解决了这个问题。