【发布时间】:2019-08-29 15:51:39
【问题描述】:
我尝试使用 CVA 创建 2 个嵌套表单。问题是当我将第二个 from 绑定到 formControl 时,它没有用数据初始化。
我有主窗体:
this.requestForm = this.fb.group({
garageId: 0,
routes: new FormArray([
new FormGroup({
addressPointId: new FormControl,
municipalityId: new FormControl,
regionId: new FormControl,
rvId: new FormControl,
sequenceNumber: new FormControl,
settlementId: new FormControl,
regionName: new FormControl,
municipalityName: new FormControl,
settlementName: new FormControl,
description: new FormControl,
})
]),
endDateTime: 0,
});
在主表单 html 中,我将路由绑定到 formArrayName。
<app-cva-form-array formArrayName="routes"></app-cva-form-array>
组件CVA-FORM-ARRAY有。
form = new FormArray([
new FormGroup({
addressPointId: new FormControl,
municipalityId: new FormControl,
regionId: new FormControl,
rvId: new FormControl,
sequenceNumber: new FormControl,
settlementId: new FormControl,
regionName: new FormControl,
municipalityName: new FormControl,
settlementName: new FormControl,
description: new FormControl,
})
]);
这里的一切都很好。我将数组中的每个 formGroup 绑定到子组件 CVA-FORM。
<app-cva-form [formControl]="route" (blur)="onTouched()"></app-cva-form>
CVA 格式 对于每个 formGroup,我创建了单独的组件,以防我想使用组件本身而不是整个数组。
form: FormGroup = new FormGroup({
regionName: new FormControl,
regionId: new FormControl,
municipalityName: new FormControl,
municipalityId: new FormControl,
sequenceNumber: new FormControl,
settlementName: new FormControl,
settlementId: new FormControl,
addressPointId: new FormControl,
description: new FormControl,
rvId: new FormControl,
});
main-form app-cva-form-array 绑定由于某种原因不起作用。
这些表格的想法来自kara's talk on angulaconnect. here are her slides.
请帮忙!
【问题讨论】:
-
不清楚你是在问背景表格吗?
-
是的。如果你看一下jsons。您会看到主窗体(背景窗体)与其他窗体不同步。
-
看看posetd的答案
标签: angular typescript angular-reactive-forms controlvalueaccessor