官术网_书友最值得收藏!

  • Essential Angular
  • Victor Savkin Jeff Cross
  • 128字
  • 2021-07-02 22:56:28

Lazy loading

As I mentioned earlier NgModules are not just the units of compilation, they are also the units of distribution. That is why we bootstrap a NgModule, and not a component—we don't distribute components, we distribute modules. And that's why we lazy load NgModules as well.

import {NgModuleFactoryLoader, Injector} from '@angular/core';

class MyService {
constructor(loader: NgModuleFactoryLoader, injector: Injector) {
loader.load("mymodule").then((f: NgModuleFactory) => {
const moduleRef = f.create(injector);
moduleRef.injector; // module injector
moduleRef.componentFactoryResolver; // all the \
components factories of the lazy-loaded module
});
}
}

The loader compiles the modules if the application is running in the JIT mode, and does not in the AOT mode. The default loader @angular/core ships with uses SystemJS, but, as most things in Angular, you can provide your own.

主站蜘蛛池模板: 宁晋县| 平武县| 乡宁县| 彭山县| 右玉县| 铁力市| 禹城市| 韶山市| 邹城市| 新泰市| 桐城市| 玉屏| 高雄县| 营山县| 金门县| 南和县| 彭山县| 江城| 雷波县| 嘉定区| 贵州省| 铁岭县| 自治县| 长春市| 镇巴县| 泰宁县| 波密县| 浦城县| 沂水县| 呈贡县| 体育| 平舆县| 海南省| 郴州市| 沅陵县| 红原县| 托克逊县| 兴隆县| 阿图什市| 忻城县| 伊川县|