我是 Angular 2 的初学者。我正在尝试创建一个具有动态表单的表,创建了表并且值也绑定但我无法访问 formControlName 中的值,尝试了下面的代码但它没有工作。
有人可以帮我在下面的代码中做错了吗
HTML
<tbody formArrayName="timetable">
<tr *ngFor="let child of timetableForm.controls.timetable.controls; let i = index;" [formGroupName]="i">
<td *ngFor="let period of child.controls.periods.controls;let j = index;" [formGroupName]="j">
{{period.controls.day.value}} <!-- bind is working fine -->
<input type="text" [formControlName]="day"> <!-- error -->
</td>
</tr>
</tbody>
TS
ngOnInit(){
this.tableForm = this.formBuilder.group({
timetable: this.formBuilder.array([
this.formBuilder.group({
periods: this.formBuilder.array([
this.formBuilder.group({
subject_id:10,
timing_id:11,
day:'Monday'
}),
this.formBuilder.group({
subject_id:10,
timing_id:11,
day:'Tuesday'
}),
this.formBuilder.group({
subject_id:10,
timing_id:11,
day:'Wednesday'
}),
this.formBuilder.group({
subject_id:10,
timing_id:11,
day:'Thursday'
}),
this.formBuilder.group({
subject_id:10,
timing_id:11,
day:'Friday'
})
])
}),
this.formBuilder.group({
periods: this.formBuilder.array([
this.formBuilder.group({
subject_id:10,
timing_id:11,
day:'Monday'
}),
this.formBuilder.group({
subject_id:10,
timing_id:11,
day:'Tuesday'
}),
this.formBuilder.group({
subject_id:10,
timing_id:11,
day:'Wednesday'
}),
this.formBuilder.group({
subject_id:10,
timing_id:11,
name:'Thursday'
})
])
})
])
});
提前致谢。