When I try to update the form, I notice that my meetupform.controls.day array is not retaining the previously selected values
app.component.html
<div *ngIf="meetupForm.controls.recurring.value==='weekly'">
<mat-checkbox (change)="onDayChange(day, $event.checked)" *ngFor="let day of days" class="margin-lr" [checked]="isClassDay(day)">{{day}}</mat-checkbox>
</div>
app.component.ts
onDayChange(day: string, isChecked: boolean) {
const dayFormArray = <FormArray>this.meetupForm.controls.day;
if (isChecked) {
// add to day array if checked
dayFormArray.push(new FormControl(day));
} else {
// remove from day array if unchecked
const index = dayFormArray.controls.findIndex(x => x.value === day);
dayFormArray.removeAt(index);
}
}