去除dcl-wapper angular2中扭曲的动态分量 [英] removing dynamic component warped in dcl-wapper angular2

查看:72
本文介绍了去除dcl-wapper angular2中扭曲的动态分量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://stackoverflow.com/questions/37154552/how-can-i-render中所述的*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屋!

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