- 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.
推薦閱讀
- Visual C++實例精通
- Raspberry Pi for Secret Agents(Third Edition)
- MariaDB High Performance
- Full-Stack React Projects
- Magento 1.8 Development Cookbook
- 精通Python設(shè)計模式(第2版)
- 深入淺出Serverless:技術(shù)原理與應(yīng)用實踐
- Apache Camel Developer's Cookbook
- Laravel Design Patterns and Best Practices
- 體驗之道:從需求到實踐的用戶體驗實戰(zhàn)
- Responsive Web Design with jQuery
- 計算機系統(tǒng)解密:從理解計算機到編寫高效代碼
- 基于JavaScript的WebGIS開發(fā)
- Java程序設(shè)計(項目教學(xué)版)
- Web程序設(shè)計與架構(gòu)