简体   繁体   English

Angular:如何在延迟加载的路由中使用外部模块

[英]Angular: How to use external module in lazy loaded routes

I install this module for my Angular project by ng add command. 我通过ng add命令为Angular项目安装了这个模块。 It imports the module in the app.module file. 它在app.module文件中导入模块。 Also, I use lazy loading modules and routes in my project. 另外,我在项目中使用延迟加载模块和路由。 I need this external module in one of my routes. 我在其中一条路线中需要这个外部模块。 I don't want to import it in app.module. 我不想在app.module中导入它。

But when I remove the import in app.module, I get the following errors: 但是当我在app.module中删除导入时,我收到以下错误:

core.js:15714 ERROR Error: Uncaught (in promise): Error: 
StaticInjectorError(AppBrowserModule)[InjectionToken nz-i18n]:
...

Am I wrong? 我错了吗? Where should I import such modules? 我应该在哪里导入这些模块? If it's lazy loading, it's not reasonable to import it in the app.module file. 如果它是延迟加载,则在app.module文件中导入它是不合理的。

尝试创建shared.module.ts并将您在应用程序中所需的所有组件/模块(通用)导入到此组件中,然后将其导入app.module.ts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM