首页 > 解决方案 > 解决 Angular 循环模块依赖和组件(父子)

问题描述

我有以下结构

Project
---Module1
------ComponentA
------componentB
---Module2
------componentC
------componentD

在导入中,Module1.module.ts我正在导入 Module2,因为在componentA我使用的componentC属于Module2.

现在,我需要componentB(Module1)在我componentD的 module2 中使用,但我有很多错误,因为我在导入时创建了循环依赖Module1Module2.module.ts

此时的结构是:Module1is parent of Module2。所以,我不知道是否存在某种方式来访问属于Module1(parent)from one 中的一个组件的一个组件Module2(Child)

标签: angulartypescriptmoduleparent-childcircular-dependency

解决方案


如果您不关心当前的模块结构,您可以为组件 B 和 C 创建第三个模块 - 您可以导入module 3module 1andmodule 2中。

Project
---Module1
------ComponentA
---Module2
------componentD
---Module3
------componentC
------componentB

推荐阅读