Currently, I am dealing with a collection of checkboxes and utilizing Angular's FormBuilder to handle my form. My objective is to link the values of the selected checkboxes to a form control named itemIds within my form group.
constructor(private formBuilder: UntypedFormBuilder
) {
}
serviceTaskForm = this.formBuilder.group({
....
itemIds : ['']
})
onCheckboxChange($event: MatLegacyCheckboxChange) {
}
Regarding my HTML code:
<form>
.....
<mat-form-field appearance="fill">
<div class="demo-select-all-checkboxes" *ngFor="let task of tasks">
<mat-checkbox
(change)="onCheckboxChange($event)"
[value]="task.itemId">
{{ previousTask.itemId }} {{ previousTask.invoice}}
</mat-checkbox>
</div>
</mat-form-field>
</form>
https://i.sstatic.net/GPIIZR7Q.png
I am aiming for the itemIds form control to be an array that includes all the selected checkbox values. Any insights on how I can achieve this?