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

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.

主站蜘蛛池模板: 滦南县| 健康| 崇明县| 永川市| 天门市| 吉林市| 苗栗县| 泰州市| 葫芦岛市| 军事| 越西县| 绍兴县| 古交市| 易门县| 来安县| 丰镇市| 江油市| 于田县| 平和县| 扶绥县| 普洱| 上杭县| 达拉特旗| 宜都市| 措勤县| 克什克腾旗| 铜梁县| 贺州市| 辛集市| 太仓市| 黄石市| 宜宾市| 岐山县| 神农架林区| 富源县| 横山县| 宜兰市| 沾益县| 城口县| 定襄县| 霍林郭勒市|