angula *ngFor 下标【转藏】

2018-12-25  本文已影响6人  追逐繁星的阿忠
<ul>
    <li *ngFor="let item of items; let i = index">     
       {{item}}
    <i (click)="deleteThis(i)">x</i>
    </li>
</ul>
private items = ["张三","李四","王五","赵六","李七"];

deleteThis(index){
  console.log(index);
  this.items.splice(index,1) //根据数组的index来删除对应的元素
}

原文地址:https://www.cnblogs.com/leiting/p/8573198.html

上一篇下一篇

猜你喜欢

热点阅读