简体   繁体   English

如何在没有 ngModule 的情况下使用 angular 加载惰性组件?

[英]how to load lazy component with angular without ngModule?

In angular is it possible to load component in lazy without specify ngModule ?在 angular 中是否可以在不指定ngModule的情况下以惰性方式加载组件?

Today I use:今天我使用:

 { path: '..', loadChildren: () => import('./my.module').then(m => m.myModule) }

Can I do something like this code:我可以做这样的代码:

 { path: '..', component: () => import('./my.component') }

Is it possible?可能吗? if so how?如果是这样怎么办?

I found this tutorial which I think can help you.我找到了这个教程,我认为它可以帮助你。 In order, you need to declare the component as part of this module, then to load component only when it's used, helped by ComponentFactoryResolver and Injector按照顺序,您需要将组件声明为该模块的一部分,然后仅在使用组件时才加载组件,由ComponentFactoryResolverInjector提供帮助

Yes, you can load component lazily without including it in NgModule.是的,你可以懒加载组件而不将它包含在 NgModule 中。 you can import component in code where you need and then by using ComponentFactory Resolver and ViewComponentRef, check the article您可以在需要的代码中导入组件,然后使用 ComponentFactory Resolver 和 ViewComponentRef,查看文章

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

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