angular - 如何在 Angular 8 中延迟加载子组件?
问题描述
我有一个包含多个模态(NgbModal)的组件。这些模态连接到多个子组件。我正在尝试延迟加载这些子组件
Dashboard Module
|
|--> Dashboard Component
|-->modal 1
|
|--> child 1 component
|--> child 2 component
|--modal 2
|--> child 3 component
|--> child 4 component
解决方案
您可以使用这样的路由延迟加载仪表板模块
// in app routing or higher routing module than dashboard
const routes: Routes = [
{ path: 'dashboard', loadChildren: () =>
import('./modules/dashboard/dashboard.module').then(m => m.DashboardModule) },
];
然后在您的仪表板路由模块中(要在 dahsboard 模块中导入),您可以进一步重复相同的过程以延迟加载子模块/组件,否则您可以直接路由子组件。
// in dashboard routing module
const routes: Routes = [
{ path: 'chilldComponent1', loadChildren: () =>
import('./modules/dashboard/components/chilldComponent1.module').then(m =>
m.chilldComponent1Module) },
{ path: 'childcomponent2', component: Childcomponent2},
];
推荐阅读
- flutter - (应用内购买)、(Firebase 消息传递)应该进入哪一层?数据层还是表示层?
- python - SystemExit 2 调用-e', '--episode', type=int, default=2000时代码编译出错,
- node.js - 如何处理 React 和 Express 应用程序使用的带导入的 TS 库?
- php - Docker PHP-Redis 和 healthcheck 的问题
- c# - 转换为字符串失败,输入字符串的格式不正确
- excel - 如何将从 SAP 提取的 Excel 文件中的数据复制到另一个 Excel 工作簿
- c# - 在 .net5.0 中 - 外部 API 响应时间太长 - httpclient
- amazon-web-services - terraform 使用 for 循环生成地图,其中包含两个不同的资源
- logging - 如何使用 TinyLog 记录运行时异常
- python - 尝试直接从编辑器读取 json 文件时发布请求错误