I'm trying to implement FormArray into my project to generate dynamic FormControls.But I'm stuck at this error which I'm not able to understand.Whenever I create a getter method to get my array from FormGroup this error pops up.I'm going to explain the error with all the details....
Error in Console
When I click at the line pointed with RED ARROW IN ABOVE IMAGE it takes me to this following line of code and points at let data = await lastValueFrom(res);
public async getScheduleData(): Promise<SchemaSchedule> {
let res = this.http.get<SchemaSchedule>(`${this.host}/api/demo-schedule`);
let data = await lastValueFrom(res);
return data;
}
When I click at the line pointed with BLUE ARROW IN ABOVE IMAGE it takes me to this following line of code and points at dayForm.get
get mondayArray(): FormArray {
return this.dayForm.get('mondayArray') as FormArray;
}
Detailed Code Related to Above Error in TS file
async ngOnInit() {
this.scheduleResult = await this.service.getScheduleData();
this.setDay(
this.scheduleResult.monday![0]
);
}
async setDay(d1: Duration) {
this.dayForm = new FormGroup({
mondayArray: new FormArray([
new FormGroup({
startTime: new FormControl(d1.startTime),
endTime: new FormControl(d1.endTime),
}),
]),
});
}
get mondayArray(): FormArray {
return this.dayForm.get('mondayArray') as FormArray;
}
When I click at the line pointed with YELLOW ARROW IN ABOVE IMAGE it takes me to this following line of code and points at index as i
<div
class="loop_class"
*ngFor="
let item of mondayArray.controls;
index as i
"
>
Detailed Code Related to Above Error in html file
<div class="formArray" formArrayName="mondayArray">
<div
class="loop_class"
*ngFor="
let item of mondayArray.controls;
index as i
"
>
<div class="dynamic_Forms" [formGroupName]="i">
<div class="from">
<select
name="from"
id="a"
class="text-sm rounded-lg focus:border-primary border border-[#BCBCBC] py-[10px] px-4 focus:outline-none"
formControlName="startTime"
[ngClass]="monState ? '' : 'hidden'"
>
<option
[value]="timing.value"
*ngFor="let timing of timingStart"
selected="{{ timing.selected }}"
>
{{ timing.time }}
</option>
</select>
</div>
<div class="divider">
<img src="/assets/icons/add.svg" alt="" />
</div>
<div class="to">
<select
name="to"
class="text-sm rounded-lg focus:border-primary border border-[#BCBCBC] py-[10px] px-4 focus:outline-none"
formControlName="endTime"
>
<option
[value]="timing.value"
*ngFor="let timing of timingEnd"
selected="{{ timing.selected }}"
>
{{ timing.time }}
</option>
</select>
</div>
</div>
</div>
</div>