没有路由器的 Angular 延迟加载模块

标签 angular typescript module lazy-loading

是否可以从通过 npm 链接与其他模块链接的急切加载的“共享”模块延迟加载模块?我收到此错误:
./src/$$_lazy_route_resource 惰性命名空间对象中的错误
未找到模块:错误:无法解析“C:project/core\src\$$_lazy_route_resource”中的“C:project/shared/src/lazy module/lazy.module.ngfactory.js”。

-project 
        - shared (linked) (eagerly loaded)
                - lazy module
        - core (link) (main app module)

这是我的 angular.json (位于核心)"lazyModules": ["../shared/src/lazy module/lazy.module"],
测试组件.ts
constructor(public injector: Injector, private loader: NgModuleFactoryLoader) { }

private moduleRef: NgModuleRef<any>;

load(): Promise<void> {
    if (this.moduleRef) {
        return Promise.resolve();
    }

    const path = 'src/lazy-module/lazy.module#LazyModule';

    return this.loader
        .load(path)
        .then(moduleFactory => {
            this.moduleRef = moduleFactory.create(this.injector).instance;
            console.warn('moduleRef', this.moduleRef);
        })
        .catch(err => {
            console.error('error loading module', err);
        });
}

ngOnInit() {
    this.load();
}

最佳答案

不,目前不可能,请查看@ritaj 对 github 上现有功能请求的评论:https://github.com/angular/angular/issues/18093

关于没有路由器的 Angular 延迟加载模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53065170/

相关文章:

python - Ubuntu 16.04 python 安装第 3 方模块 ffmpeg-3.0.2

angular - 在 ng-sidebar 中显示 nb-datepicker

angular - 没有卡住的ionic 2异常处理

angular - 如何通过 Angular 4 中的共享模块正确导入 Angular Material 模块?

typescript - 是否有像 "explicit-function-return-type"这样不需要 void 类型的规则?

php - ZF2 : Custom user mapper for ZfcUser module

objective-c - 为什么在 Swift 中继承自 NSObject 的类会变成 public?

javascript - Select - Angular 2 的设定值

angular - 如何为 In Angular 4 中的文本字段设置默认值?

reactjs - 使用 TypeScript 为 Redux、路由器和动态模块设置 React-Testing-Library