Is there a way to lazy load components, not modules, in Angular?

后端 未结 4 2020
南方客
南方客 2021-02-18 16:00

Lazy loading is a commonly used technique. However, in Angular it seems that the granularity level of this technique stops at the module level.

That means that you ca

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-18 16:14

    Currently (Angular 8 timeframe) there are two 3rd party libraries that make lazy-loading of components easier:

    • ngx-loadable: https://github.com/mohammedzamakhan/ngx-loadable
    • hero-loader: https://www.npmjs.com/package/@herodevs/hero-loader

    Note: both of these libraries are built upon NgModuleFactoryLoader, which is deprecated in Angular 8, but there is no alternative yet ... 


    • Class marked as deprecated: https://angular.io/api/core/NgModuleFactoryLoader 

    • Explanation of Rob Wormald of the Angular Team: https://twitter.com/robwormald/status/1143981312237137925

    The Angular team has announced that lazy loading of components should become easier with Ivy (Angular 9?), but it is not clear yet how this will look like...

提交回复
热议问题