- 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.
推薦閱讀
- Extending Jenkins
- Google Flutter Mobile Development Quick Start Guide
- 從零開始:數(shù)字圖像處理的編程基礎與應用
- 算法訓練營:入門篇(全彩版)
- Mastering Natural Language Processing with Python
- 三維圖形化C++趣味編程
- DevOps入門與實踐
- C語言程序設計立體化案例教程
- Julia高性能科學計算(第2版)
- Android Wear Projects
- Java網絡編程實戰(zhàn)
- Java零基礎實戰(zhàn)
- Clojure for Machine Learning
- Bootstrap for Rails
- ABAQUS6.14中文版有限元分析與實例詳解