One of my components is set up to receive an object containing employee records and display them in a table. Each record includes a checkbox that allows users to "select" the employee for inclusion in the next process.
<tr *ngFor="let i of importResults" >
<td>
<input type="checkbox"
value="{{ i.QID }}"
attr.data-employeename="{{ i.PreferredName }} {{ i.LastName }}"
[checked]="isSelected" />
</td>
<td>{{ i.PreferredName }} {{ i.LastName }}</td>
</tr>
To manage this selection, I have created an array called selectedEmployees = [];
. The idea is that when a user clicks on a checkbox, its value should be added to the array. Similarly, if the checkbox is unchecked, the value should be removed from the array.
I initially tried using ngModel
for two-way binding, but encountered issues due to the lack of an initial checked value in the object. Is there a better approach to achieving this functionality?
While exploring solutions, I came across a related question on Stack Overflow, but encountered an error in Typescript regarding the use of .entries
. Could this be due to compatibility issues with older versions of Angular?