【发布时间】:2018-03-29 13:09:45
【问题描述】:
在 Angular2 中如何最好地显示和隐藏子组件?
我有一个父组件和三个子组件。
默认情况下onInit需要隐藏所有子组件。 而childComponentA需要在父组件中显示一个按钮的onclick。
流程:
我在 childComponentA 中有一个按钮需要在点击时显示 childComponentB,而 childComponentB 组件有一个按钮需要显示 childComponentC。就像一个展示和隐藏的流程。
如何做到最好?
可能的解决方案?
我正在考虑创建一个服务,所有子组件都订阅以显示和隐藏。但不确定它是否是最佳解决方案。
父组件 HTML:
<section>
<button (click)="showChildComponentA()"></button>
<childComponentA></childComponentA>
<childComponentB></childComponentB>
<childComponentC></childComponentC>
</section>
【问题讨论】:
标签: angular typescript