【发布时间】:2021-11-23 17:56:52
【问题描述】:
我有一个问题提出here。
我有一个ParentComponent 有一个孩子ChildComponent,
并且 child 里面有ParentComponent 所以这里有一个循环。
这是我面临的错误:
✖ Compiling with Angular sources in Ivy partial compilation mode.
ERROR: projects/api/src/lib/api.component.ts:3:1
error NG3003: One or more import cycles would need to be created to
compile this component, which is not supported by the current compiler
configuration.
The component 'ParentComponent' is used in the template but importing
it would create a cycle:
/lib/child/child.component.ts -> /lib/parent/parent.component.ts -> /lib/child/child.component.ts
这个错误只发生在 Angular 库中。如您所见,stackblitz 示例中没有问题,这只是一个演示。
在库的 tsconfig.lib.prod.json 文件中设置 "compilationMode": "full" 会消除此错误,但在这种情况下,我们会失去向后兼容性! ???
官方文档说:
将相互引用的类移动到同一个文件中,以避免它们之间的任何导入。 块引用
【问题讨论】:
标签: angular circular-dependency angular-library angular12 angular-ivy