在父模块中使用延迟加载的组件?
Use lazy loaded components in parent module?
我有一个父模块(app.module)和一个子模块(contacts.module)。子模块是延迟加载的。父模块使用子模块中的一个组件,但是当我导航到子路由时出现错误:
'app-contacts-home' is not a known element:
1. If 'app-contacts-home' is an Angular component, then verify that it is part of this module.
2. If 'app-contacts-home' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to
显然该组件不是父模块的一部分,因为它是延迟加载的。我尝试在 contacts.module 中添加 app-contacts-home
作为 entryComponent
但没有成功。
如何在父组件中使用惰性加载组件?
不,您不能在父模块中使用子延迟加载模块中的组件。
在这些情况下,您应该做的是制作第三个模块 (SharedModule),该模块将包含两个模块的组件中使用的组件。然后在父子模块中导入第3个模块,第3个模块不会被延迟加载。
此页面中的文档 https://angular.io/guide/sharing-ngmodules 提供了相关的有用信息。
希望对您有所帮助!
我有一个父模块(app.module)和一个子模块(contacts.module)。子模块是延迟加载的。父模块使用子模块中的一个组件,但是当我导航到子路由时出现错误:
'app-contacts-home' is not a known element:
1. If 'app-contacts-home' is an Angular component, then verify that it is part of this module.
2. If 'app-contacts-home' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to
显然该组件不是父模块的一部分,因为它是延迟加载的。我尝试在 contacts.module 中添加 app-contacts-home
作为 entryComponent
但没有成功。
如何在父组件中使用惰性加载组件?
不,您不能在父模块中使用子延迟加载模块中的组件。
在这些情况下,您应该做的是制作第三个模块 (SharedModule),该模块将包含两个模块的组件中使用的组件。然后在父子模块中导入第3个模块,第3个模块不会被延迟加载。
此页面中的文档 https://angular.io/guide/sharing-ngmodules 提供了相关的有用信息。
希望对您有所帮助!