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

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.

主站蜘蛛池模板: 韩城市| 马山县| 界首市| 波密县| 沾益县| 宣恩县| 灵石县| 仁布县| 渑池县| 朝阳区| 大关县| 无棣县| 东宁县| 贺州市| 喀喇沁旗| 山丹县| 大埔县| 侯马市| 孝昌县| 承德市| 太康县| 临泽县| 海兴县| 雷山县| 武乡县| 通化县| 开封市| 荔浦县| 玛沁县| 金山区| 金溪县| 商城县| 周口市| 崇明县| 宁安市| 将乐县| 开封县| 通榆县| 绥阳县| 眉山市| 剑川县|