angular - Angular File Upload Change 事件未传递正确的 ngFor 索引
问题描述
<div formArrayName="employee" *ngFor="let document of employeeForm.get('ems').controls; let i = index">
<input id="file_up" type="file" (change)="upload($event,i,document.get('name').value)"/>
</div>
When Any file is selected and its change event is called it is passing the initial value of index I, not the current value? 如何在 change 事件中获取 I 的当前值被调用?
解决方案
在这种动态循环中,总是尝试给一个trackBy
函数*ngFor
<div formArrayName="employee" *ngFor="let document of employeeForm.get('ems').controls; let i = index; trackBy: trackByFun">
<input id="file_up" type="file" (change)="upload($event,i,document.get('name').value)"/>
</div>
在 .ts
trackByFun(index, object){
return index;
}
推荐阅读
- c++ - 覆盖函数的异常规范比基础版本更宽松
- java - ConstraintValidator 的自定义消息
- react-native - how to pass props to react-native when using React native web?
- reactjs - 十进制格式数 React
- powershell - 在 PowerShell 中使用枚举类型
- android - mpandroidchart中折线图的滚动完成监听器
- linux - 使用特定行删除多个目录中的文件
- javascript - 如何将用于创建密码的iv存储在nodejs的createcipheriv中,以供将来解密?
- r - R 数据表。需要使用分组和复杂条件过滤修改列
- android - Android:三星 Galaxy S5 上的浮点虚拟键盘