angular4 *ngFor获取index
angular 中的*ngFor指令的使用
<ul>
<li *ngFor="let item in items">{{item}}</li>
</ul>
有时候需要获取index,比如删除本行li列表的时候需要根据index来确定删的是哪个
<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来删除对应的元素
}
把列表遍历出来显示到页面,点击每个列表对应的x就可以删除本条记录
angular4 *ngFor获取index的更多相关文章
- 排序并获取index的顺序
//排序并获取index的顺序:4,7,2,9-->9,7,4,2-->4,2,1,3 Array.prototype.getIndex=function(){ var orderLeng ...
- elementui el-upload 在v-for里使用时 如何获取index
<div v-for = 'item in list'> <div @click="getImageTypeIndex(index)"> <el-up ...
- java增强for循环中获取index
java增强for循环中获取index http://rensanning.iteye.com/blog/2003205
- [Angular 2] *ngFor with index
Let's see how to track index when we use 'ngFor: <li *ngFor="#hero of heros | async, #i = in ...
- Thymleaf中th:each标签遍历list如何获取index
简单介绍:传递给后台一个String类型的list,需要获取到list的每一个元素,然后进行筛选,得到正确的文本值,看代码就明白了 代码: //后台java代码//failList是一个String类 ...
- 微信小程序获取index索引值的方法
功能:点击某一项,底部出现粉色边框 首先需要通过 bindtap 为每一个item项绑定一个点击事件,其次需要添加自定义属性 data-* = {{index}} ,以便在函数中获取到被点击item项 ...
- Thymeleaf中each标签遍历list如何获取index
<tr th:each="user,userStat:${users}">userStat是状态变量,有 index,count,size,current,even,o ...
- layer弹出层 获取index
function closelayer(){ var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index ...
- java8在Stream的forEach操作时获取index
import java.util.Objects; import java.util.function.BiConsumer; /** * * @author yangzhilong * @dat ...
随机推荐
- max_int和-1
#include <stdio.h> int main(int argc, char *argv[]) { unsigned ; ) printf("umax:%u == -1\ ...
- samba 文件和目录权限控制
[laps_test] comment = laps_test path = /home/laps browseable = yes w ...
- CBiontCache
/************************************************************************/ /* 预先加载一些生物以备将来使用 */ /* 专 ...
- What is purpose of @ConditionalOnProperty annotation?
http://stackoverflow.com/questions/26394778/what-is-purpose-of-conditionalonproperty-annotation **** ...
- 在form action中滥用绝对路径导致session的attribute丢失(无法正常保存)
症状: 刚才在做一个利用session的attribute保存用户的id的实验,login.jsp输入用户id,提交给LoginServlet去数据库验证,然后LoginServlet根据验证情况跳转 ...
- Linux动态库开发
http://blog.csdn.net/qq_33850438/article/details/52014399 ### 导出符号------------------------------ 默认所 ...
- java strtus2 拦截器(Interceptors)
在strtus2 中有一个比较重要的东西就是拦截器(Interceptors) 拦截器可以做到在已有的业务中插入一块共通的,比如在一个业务中,直接插入一串登录功能,就不用去每个页面一个个去显示是否登录 ...
- spring配置:context:property-placeholder 读取配置文件信息 在配置文件中使用el表达式填充值
spring将properties文件读取后在配置文件中直接将对象的配置信息填充到bean中的变量里. 原本使用PropertyPlaceholderConfigurer类进行文件信息配置.Prope ...
- linux 域和xenomai 实时域之间的交互
/* * XDDP-based RT/NRT threads communication demo. * * Real-time Xenomai threads and regular Linux t ...
- HashMap与ConcurrentHashMap的区别(转)
从JDK1.2起,就有了HashMap,正如前一篇文章所说,HashMap不是线程安全的,因此多线程操作时需要格外小心. 在JDK1.5中,伟大的Doug Lea给我们带来了concurrent包,从 ...