[英]How to make dropdown list populated in loop in Angular 6 HTML?
I have an array of employees to which tests are assigned by Lead.我有一组员工,Lead 为其分配了测试。 When assigning tests, selected employee is assigned properly.分配测试时,正确分配选定的员工。 while populating back, Lead can see which test is assigned to which employee.在填充回来时,Lead 可以看到哪个测试分配给了哪个员工。
I am facing issue is, EmployeeID is populated correct but its corresponding employee name is different.我面临的问题是,EmployeeID 填充正确,但其对应的员工姓名不同。
Employee id and names are like <1, FName1>, <2, FName2>, <3, FName3>, <4, FName4>员工 ID 和姓名类似于 <1, FName1>, <2, FName2>, <3, FName3>, <4, FName4>
<table class="table table-bordered table-sm m-0 w-auto">
<tbody>
<tr *ngFor="let t of tests">
<td>
{{t.empid}} //Correct EmployeeID populated
<select *ngIf="t" id="assigned" name="assignedName" [(ngModel)]="t.empid" class="form-control">
<option *ngFor="let e of empids; let i = index" [value]="empids[i].employeeid">
{{empids[i].employeename}} //Wrong employee Name populated
</option>
</select>
</td>
</tr>
</tbody>
</table>
Screenshot of result is as below where employeeID is populating correctly but EmployeeName is wrong.结果的屏幕截图如下所示,employeeID 正确填充但 EmployeeName 错误。
Thanks in advance.提前致谢。
Screenshot after updating code to e.employeename将代码更新为 e.employeename 后的屏幕截图
You can just use e.employeename
like you did for the value e.employeeid
您可以像使用e.employeename
一样使用e.employeeid
<select *ngIf="t" id="assigned" name="assignedName" [(ngModel)]="t.empid" class="form-control">
<option *ngFor="let e of empids; let i = index" [value]="e.employeeid">
{{e.employeename}} // Change your code here
</option>
</select>
You don't actually need to reference the index in this case.在这种情况下,您实际上不需要引用索引。
Your current HTML您当前的 HTML
<option *ngFor="let e of empids; let i = index" [value]="empids[i].employeeid">
{{empids[i].employeename}} //Wrong employee Name populated
</option>
Can be updated to可以更新为
<option *ngFor="let e of empids; let i as index" [value]="e.employeeid">
{{e.employeename}}
</option>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.