Angular 4-以编程方式删除当前动态组件 [英] Angular 4 - Remove current dynamic component programmatically
本文介绍了Angular 4-以编程方式删除当前动态组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一些动态组件,例如-
I have created some dynamic components like -
<div>
<ang-textfield></ang-textfield>
<ang-textarea></ang-textarea>
<ang-checkbox></ang-checkbox>
</div>
在特定的dynamic component
中,有一些元素--
Within specific dynamic component
there are some elements like -
<ang-textfield>
<input type="text" />
<button>Settings</button>
<button (click)="remove_component()">Remove</button>
</ang-textfield>
我想在单击Remove
按钮后删除当前组件.
I want to remove current component after clicking Remove
button.
我该怎么做?
这是朋克车
Here is the plunker
推荐答案
您可以将组件工厂作为对动态构建组件的引用,然后在动态组件中单击销毁".
You can Pass the component factory as a Reference to the Dynamic Build Component and then in the Dynamic Component Have a button Destroy .
此 要点 会给您一个更清晰的主意.
This Gist will give you a Clearer Idea.
实时> 示例
这篇关于Angular 4-以编程方式删除当前动态组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文