小编ADA*_*lin的帖子

从 Angular 7 中的编译库延迟加载模块

我正在尝试从库中延迟加载 NgModule。我有一个 ng 应用程序,其中包含一些库(项目)。这个库在其他一些项目中被重用。问题是我找不到解决方案,它适用于 jit 和 aot,以及编译/未编译库。

文件结构是这样的

app
-projects
--lib
---(lib files)
-src
--(app files)
Run Code Online (Sandbox Code Playgroud)

AppModule 有路由,看起来像这样

const routes: Routes = [
    {
        path: 'eager',
        children: [
            {
                path: '',
                component: LibComponent // component imported from lib
            },
            {
                path: 'lazy',
                loadChildren: 'lib/src/lib/lazy/lazy.module#LazyModule' // module i want to load lazily
            }
        ]
    }
];
Run Code Online (Sandbox Code Playgroud)

如果我像这样使用它,则在尝试导航到 jit 中的惰性路由时会出现运行时错误(aot 工作正常): ERROR Error: Uncaught (in promise): TypeError: undefined is not a function TypeError: undefined is not a function

此评论https://github.com/angular/angular-cli/issues/9488#issuecomment-370065452建议不要将 LazyModule …

jit lazy-loading angular-cli angular

6
推荐指数
1
解决办法
5945
查看次数

标签 统计

angular ×1

angular-cli ×1

jit ×1

lazy-loading ×1