简体   繁体   中英

Angular lazy loading module without router

is it possible to lazy load module from eagerly loaded "shared" module which is linked with other modules via npm link? I am getting this error: ERROR in ./src/$$_lazy_route_resource lazy namespace object Module not found: Error: Can't resolve 'C:project/shared/src/lazy module/lazy.module.ngfactory.js' in 'C:project\\core\\src\\$$_lazy_route_resource'.

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

This is my angular.json (located in core) "lazyModules": ["../shared/src/lazy module/lazy.module"],

test.component.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();
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM