首页 > 解决方案 > 如何实现第 3 层子组件

问题描述

app.component 是我的顶层。- 子层 1 --子层 2。

我想<app-childlayer2></app-childlayer2>在 child-layer1.html 中使用。

我必须在 app-module.ts 和 app-childlayer1.ts 中进行哪些导入和声明?

这可以在不添加模块的情况下完成吗?

标签: angular

解决方案


据我所知,您无需单独进行任何特殊的导入或声明。使用ng generate component命令创建新组件,它会自动修改你的 app.module.ts。使用以下命令建立良好的文件夹结构。

ng g c components/child-layer-1
ng g c components/child-layer-1/child-layer-2
...

还可以使用 @input、@ouput 装饰器在组件之间共享数据 https://medium.com/@chameeradulanga87/sharing-data-between-angular-components-f76fa680bf76

如果有什么需要改变的,请评论@others


推荐阅读