Angular 6/7默认使用Eager/Lazy加载吗? [英] Angular 6/7 by default uses Eager/Lazy loading?

查看:67
本文介绍了Angular 6/7默认使用Eager/Lazy加载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我们是否需要为模块手动实现延迟加载,还是默认情况下Angular 6/7会这样做?

As the title says, do we need to manually implement Lazy Loading for the modules or does Angular 6/7 does it by default?

推荐答案

除非另有说明,否则默认情况下,Angular会使用紧急加载.

Angular by default uses eager loading unless specified otherwise.

要实现延迟加载,需要在RouterModule中指定以下内容:

To implement Lazy Loading, following things need to be specified to the RouterModule:

  1. 具有loadChildren而不是component的路由配置对象.为其分配的值将是延迟加载的模块"的相对路径,后跟#,后跟模块的名称.

  1. A route config object with loadChildren instead of component. The value assigned to it would be the relative path to the Lazy Loaded Module, followed by # followed by the name of the module.

惰性加载的模块还应该在其中实现路由模块,并且在其中应调用forChild而不是forRoot.

The Lazy loaded module should also implement a routing module in it and in there, it should call forChild instead of forRoot.

Angular官方提供了一个非常不错的 指南 您可以遵循的文档来实现模块的延迟加载.

There's a very nice guide provided on Angular's Official Docs that you can follow to implement Lazy Loading of modules.

这是一个 示例StackBlitz ,您可以按照其实现延迟加载.

Here's a Sample StackBlitz that you can follow to implement Lazy Loading.

这篇关于Angular 6/7默认使用Eager/Lazy加载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆