首页 > 其他 > 详细

Angular 中自定义模块

时间:2020-05-26 20:36:58      阅读:40      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

一、Angular 内置模块

 

 技术分享图片

 

 

 二、Angular 自定义模块

当我们项目比较小的时候可以不用自定义模块。但是当我们项目非常庞大的时候把所有的组


件都挂载到根模块里面不是特别合适。

 

所以这个时候我们就可以自定义模块来组织我们的项目。并且通过 Angular 自定义模块可以实现路由的懒加载。

 

 

例如,创建商品模块:

ng g module module/product:

product.module.ts

创建模块的根组件:product组件

ng g component module/product

技术分享图片

 

 创建其他组件:

ng g component module/product/components/plist

ng g component module/product/components/cart

ng g component module/product/components/pinfo

技术分享图片

 

 把product.ts的根组件暴露出去

exports:[ProductComponent]

技术分享图片

 

 在根模块app.module.ts挂载根模块

技术分享图片

 

 之后可以在根组件.html调用商品模块

 

Angular 中自定义模块

原文:https://www.cnblogs.com/foremostxl/p/12968256.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!