如何在Angular2中隐藏和替换组件 [英] How to hide and replace a component in Angular2

查看:43
本文介绍了如何在Angular2中隐藏和替换组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个父级组件(A),并且有2个子级组件(B和C).父级A默认情况下显示子组件B.现在,当单击父级A上显示的按钮时,它将用子组件C替换子组件B.在angular2中单击按钮后,如何用组件C替换组件B?/p>

Hello i have a parent component (A) and it has 2 child components (B and C). Parent A by default displays child component B. Now when a button is clicked that is displayed on parent A, it replaces child component B with child component C. How can i replace component B with Component C after the button is clicked in angular2?

推荐答案

为此,您可以使用

To do that you can use the *ngIf directive or the hidden property.

请注意区别:

  • * ngIf 删除并重新创建元素:
  • *ngIf removes and recreates the element:

如果分配给ngIf的表达式的计算结果为假值,则元素已从DOM中删除,否则该元素的克隆为重新插入DOM.

If the expression assigned to ngIf evaluates to a false value then the element is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆