去除dcl-wapper angular2中扭曲的动态分量 [英] removing dynamic component warped in dcl-wapper angular2
问题描述
我正在使用*ngFor
组件和*ngFor
组件,通过组件数组渲染动态创建的组件. -a-component-that-implements-an-interface#37154680>此答案
I'm rendering dynamically created components from a component array with *ngFor
with a <dcl-wrapper [type]="t"></dcl-wapper>
component described in this answer
我正在尝试向该组件添加一个删除按钮,以便可以通过myCompArray.splice(index, 1)
单击按钮时删除该组件,但是始终删除了最后一个组件.
这是我的朋克 http://plnkr.co/edit/4lhuHF?p=preview
I'm trying to add a remove button to the component so I could remove the component on button click with myCompArray.splice(index, 1)
but it allways removes the last one
here is my plunker http://plnkr.co/edit/4lhuHF?p=preview
推荐答案
传递索引,而不传递事件.该事件为null
,因为未发出任何值:
Pass the index, not the event. The event is null
because no value was emitted:
(removed)=onRemoved(i)
您还应该注意,当删除或添加项目时,[index]=i
会更新其余元素的@Input() index;
属性.
You should also be aware that [index]=i
updates the @Input() index;
property on the remaining elements, when an item was removed or added.
这篇关于去除dcl-wapper angular2中扭曲的动态分量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!