【发布时间】:2018-12-17 02:53:23
【问题描述】:
我想从我的父组件中动态删除组件。
<div>
<my-component #component
(remove)="onRemove(0)">
</my-component>
<my-component #component
(remove)="onRemove(1)">
</my-component>
<my-component #component
(remove)="onRemove(2)">
</my-component>
</div>
子组件发射到父组件,它在 onRemove 函数中起作用:
constructor(private generalViewContainerRef: ViewContainerRef) {
}
private onRemoveWidget(index:number) {
this.generalViewContainerRef.remove(component);
}
但它不起作用。
我该怎么做?
【问题讨论】:
-
你能量化不工作吗?你有错误吗?还是其他行为?
-
没有错误也没有行为,什么也没有发生
-
如果你想动态删除检查这个stackoverflow.com/questions/44939878/…