Angular 6组件中的循环依赖

时间:2018-09-18 12:11:00

标签: angular

我有三个角形材质对话框,单击后退按钮应该会打开上一个对话框,但是当我尝试这样做时,我遇到了循环依赖问题

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)

2 个答案:

答案 0 :(得分:0)

如果这是您要为其添加组件的服务,则可以将该组件添加为方法参数,并通过该组件添加服务方法。

答案 1 :(得分:0)

我发现了问题的根本原因,这是因为我试图从对话框b中打开对话框a,然后再次单击从对话框b到a的返回按钮。 我通过单击“后退”按钮使用“行为主题”解决了该问题。

相关问题