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

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.

主站蜘蛛池模板: 潼关县| 樟树市| 大田县| 宁国市| 麻阳| 肥城市| 介休市| 江油市| 苏尼特左旗| 墨玉县| 诸暨市| 潍坊市| 九寨沟县| 牙克石市| 安乡县| 志丹县| 阿合奇县| 克什克腾旗| 诸暨市| 林甸县| 常德市| 隆昌县| 博湖县| 迁安市| 康平县| 伊金霍洛旗| 兰州市| 凌云县| 梁山县| 吕梁市| 互助| 南木林县| 蓝田县| 隆安县| 兴宁市| 晋江市| 教育| 渝北区| 新密市| 乌兰浩特市| 容城县|