Angular 嵌套表单组、表单数组的问题
我使用的是表格组。在这里,我声明了一个表单数组。在内部 表单数组,我为组动态声明。问题是什么时候 我正在更新表单组中的值,仅更新来自组值的内部值 和表单数组值正在更新,但外部表单组值未更新 更新Angular 嵌套表单组、表单数组的问题,angular,Angular,我使用的是表格组。在这里,我声明了一个表单数组。在内部 表单数组,我为组动态声明。问题是什么时候 我正在更新表单组中的值,仅更新来自组值的内部值 和表单数组值正在更新,但外部表单组值未更新 更新 this.fiscalYearForm = new FormGroup({ fiscalYear: new FormControl(""), startDate: new FormControl(""), endDate: new FormControl(""), description
this.fiscalYearForm = new FormGroup({
fiscalYear: new FormControl(""),
startDate: new FormControl(""),
endDate: new FormControl(""),
description: new FormControl(""),
isCreateFiscalPeriod: new FormControl(false),
noOfFiscalPeriods: new FormControl(),
fiscalPeriods: this.fb.array([])
});
let control = <FormArray>this.fiscalYearForm.controls.fiscalPeriods;
control.push(
this.fb.group({
periodName: ["", Validators.required],
periodStartDate: ["", Validators.required],
periodEndDate: ["", Validators.required],
periodDescription: [""]
})
);
this.fiscalYearForm=新表单组({
财政年度:新的FormControl(“”),
startDate:new FormControl(“”),
结束日期:新的FormControl(“”),
说明:新表单控件(“”),
isCreateFiscalPeriod:新表单控件(false),
NoOfficesPeriods:新建FormControl(),
fiscalPeriods:this.fb.array([])
});
让control=this.fiscalYearForm.controls.fiscalPeriods;
控制按钮(
本集团({
periodName:[“”,验证器。必需],
periodStartDate:[“”,验证器。必需],
periodEndDate:[“”,验证器。必需],
periodDescription:[“”]
})
);
我还需要外部表单组中的值。但是它没有更新。
我还需要外部表单组中的值
,您对此的确切含义是什么?至少我很难理解你的意思。我觉得你的代码很好。另外,我花了20分钟的时间创建了一个表单,试图在上面复制这个问题,您可能已经在模板中做了一些事情。查看示例stackBlitz,看看有什么问题。通过在更新外部表单组的位置添加行来更新代码。我看到了stackBlitz代码,这里我是这样使用的,我不知道问题发生在哪里。但我已经解决了这个问题,添加了这个.fiscalYearForm.updateValueAndValidity();
this.fiscalYearForm = new FormGroup({
fiscalYear: new FormControl(""),
startDate: new FormControl(""),
endDate: new FormControl(""),
description: new FormControl(""),
isCreateFiscalPeriod: new FormControl(false),
noOfFiscalPeriods: new FormControl(),
fiscalPeriods: this.fb.array([])
});
let control = <FormArray>this.fiscalYearForm.controls.fiscalPeriods;
control.push(
this.fb.group({
periodName: ["", Validators.required],
periodStartDate: ["", Validators.required],
periodEndDate: ["", Validators.required],
periodDescription: [""]
})
);