We mainly need a dynamic ngModel in case of creating a dynamic text field.
In your TS file
export class AppComponent { public selectedBranch: any[] = [0]; public selectedShiftNameTime: any[] = [0]; public CustomDates: any[] = [0]; }
your HTML file (template)
<table class="table" style="padding: 20px;"> <tr> <td class="col-md-2">Employee Name</td> <td class="col-md-2">Branch</td> <td class="col-md-2">Shift Type</td> <td class="col-md-2">Custom Dates</td> </tr> <tr *ngFor="let emp of Empdata"> <td> <label> {{emp.name}} </label> </td> <td> <select class="form-control rounded-0" id="selectedBranch{{emp.EmployeeInfoId}}" > <option value='0'>--Select--</option> <option *ngFor="let branch of Branchdata" [value]=branch.BranchId> {{branch.BranchName}} </option> </select> </td> <td> <select class="form-control rounded-0" id="selectedShiftNameTime{{emp.EmployeeInfoId}}" > <option value='0'>--Select--</option> <option *ngFor="let shifType of ShiftTypedata" [value]=shifType.ShiftTypeId> {{shifType.ShiftName}} </option> </select> </td> <td> <ng-multiselect-dropdown [placeholder]="'Select Custom Dates'" [data]="dropdownList" id="CustomDates{{emp.EmployeeInfoId}}" [(ngModel)]="CustomDates[emp.EmployeeInfoId]" [settings]="dropdownSettings" (onSelect)="onItemSelect($event)" (onSelectAll)="onSelectAll($event)"> </ng-multiselect-dropdown> </td> </tr> <tr> <td colspan="4" > <button type="button" (click)='submit()' >Submit</button> </td> </tr> </table>
source share