angular - 如何实现第 3 层子组件
问题描述
app.component 是我的顶层。- 子层 1 --子层 2。
我想<app-childlayer2></app-childlayer2>
在 child-layer1.html 中使用。
我必须在 app-module.ts 和 app-childlayer1.ts 中进行哪些导入和声明?
这可以在不添加模块的情况下完成吗?
解决方案
据我所知,您无需单独进行任何特殊的导入或声明。使用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
推荐阅读
- python - 渲染views.py“Django”时我很困惑
- regex - Perl 锚定的正则表达式性能
- java - 基于请求的不同属性和基于java中的请求的不同顺序排序(不是重复的)
- go - 在 GO 中解组嵌套的 JSON 对象
- javascript - 通过 console.log([...mapObject.entries()]) 将类似于控制台输出的地图转换为字符串
- python - 计算变压器结果指标的最佳方法是什么?
- javascript - 试图简化这个处理 undefined 的 JavaScript 表达式
- reactjs - 为什么 Material-UI 不允许在此处进行自定义转换?
- c++ - 据称依赖于自身的 C++20 概念
- flutter - 我如何让动画类从其他飞镖文件中获取孩子