首页 > 解决方案 > 如何加载包含动态惰性模块的Angular库?

问题描述

我正在尝试这样做:

通常我们在routing.ts中添加这样一个惰性模块,

{路径:'taskCenter',loadChildren:'./taskCenter/taskCerter.module#TaskCenterModule'},

现在,我想从 rollup 或 ng-packagr 生成的包中加载Children Dynamic!动态的!

eg:Aot构建后,当url为'localhost:4200/#/taskCenter'时,会从assets文件夹中动态加载taskCenter.umd.js及其子模块

首先,我们如何将所有惰性模块打包到库中?那么,如何动态加载这个模块呢?

// First, in Library ,how to package all code including TestChildrenModule
@NgModule({
  imports: [
    RouterModule.forChild([
      {
        path: '', pathMatch: 'full', component: ModuleaComponent
      },
      { path: 'aa', loadChildren: './test-children/test-children.module#TestChildrenModule' }
    ])
  ],
  declarations: [ModuleaComponent],
  exports: [ModuleaComponent]
})
export class ModuleaModule { }

此链接可能会有所帮助:https ://github.com/lmeijdam/angular-umd-dynamic-example

标签: javascriptangularlazy-loading

解决方案


延迟加载应该发生在应用程序而不是库级别

从这个讨论:文章链接


推荐阅读