angular中的组件嵌套
1 创建3个包:
header-module
main-module
sliderbar-module
2 在header-module创建三个组件
header-center
heder-left
header-right
3 z将三个组件嵌套入header-module包里面
1):在header-module.modules.ts文件中引入三个组件,且在declarations中声明
注意:exports:[放置外部需要调用的component文件]
imports:[调用文件所需要的Module包]
declarations:[放置的是这个包里面所有嵌套的组件Component]
4 在header-module.component.html文件中引入组件
注意:引入组件的名称需要按照各个组件中的ts文件中的selector命名规范命名
5 在app.modules.ts文件中引入header-module.modules.ts包
header-module.component.html内操作
以上操作就已经把header-module包里面的组件嵌套在header-module包里面并且成功挂在app.html文件中显示在页面上。
接下来将main-module, 让slidebar-module包内组件在app.html文件中显示
main-module内文件
HTML:
component.ts:不需要修改东西
module.ts
app.module.ts内:
app.component.html内:
slidebar-module里面的操作跟main-module里面的操作一样
最后的自己添加一些样式结果: