Angular5在延迟加载模块中使用外部组件

发布于 2025-01-09 20:48:41 字数 351 浏览 5 评论 0原文

我有一个惰性加载的 LazyModule,以及另一个 ModuleA。我需要在 LazyModule 中使用组件 Module-A-Component 。我如何访问这个外部组件?我在所有应用程序中使用 Module-A-Component。

如果我在 LazyModule 的声明数组中添加 Module-A-Component 会出现错误:

Module-A-Component 是 2 个模块声明的一部分...

如果我仅在 LazyModule 中移动 Module-A-Component,我就无法在应用程序的其他部分使用它。

如何在延迟加载模块和其他模块中使用外部组件?

I has LazyModule which I load lazy, and another one ModuleA. I need to use component Module-A-Component inside LazyModule. How can I access this external component? I use Module-A-Component around all application.

If I add Module-A-Component in daclaration array of LazyModule got the error:

Module-A-Component is part of the declarations of 2 modules...

If I move Module-A-Component only in LazyModule I can't use it in other parts of application.

How can I use the external component in lazy loaded module and other modules?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾家有女初长成 2025-01-16 20:48:41

由于没有代码,所以我将给出理论上的答案。您需要创建一个共享模块。在其中创建 Module-A-Component 并相应命名。然后在 MOdule AMOdule-B 等中重用它。

这也将确保不存在循环依赖。

Since there is no code, so I am gonna give a theoretical answer. You need to create a shared-module. Create Module-A-Component inside it and name it accordingly. Then reuse it in MOdule A , MOdule-B and so on.

This will also make sure that there are no circular dependecy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文