I have a component that receives an object of employee records and displays them in a table. Each record has a checkbox that allows you to "select" the employee to be included 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>
In this component, I created an array selectedEmployees = []; and my goal is that when I click a checkbox, its value is pushed to the array, as well as when I uncheck it, the value is removed from the array.
I tried using ngModel for 2 way binding but because this data doesn't have an initial checked value in the object, I wasn't able to get that working correctly.
Is ngModel the best way to achieve this? Perhaps I was just going about it the wrong way.
I tried following this question but typescript threw an error saying .entries was not valid. It may have been for an older version of angular?
importResults.filter(i => i.isSelected)to only select the selected employees. You can store that result on a field in your component and pass that field into the sibling component. You will need to use ngModel for that.