- 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.
推薦閱讀
- FuelPHP Application Development Blueprints
- Learn Type:Driven Development
- LabVIEW入門與實戰開發100例
- Bootstrap Essentials
- Symfony2 Essentials
- OpenStack Orchestration
- C語言程序設計
- HTML5 APP開發從入門到精通(微課精編版)
- Regression Analysis with Python
- Access 2010數據庫應用技術實驗指導與習題選解(第2版)
- C++程序設計教程(第2版)
- Mastering Concurrency Programming with Java 9(Second Edition)
- 大話代碼架構:項目實戰版
- C語言王者歸來
- GO語言編程從入門到實踐