angular2 formbuilder多嵌套formGroupName
angular2 formbuilder multi-nested formGroupName
我遇到以下错误:
EXCEPTION: Uncaught (in promise): Error: Error in ./AccComponent class AccComponent - inline template:106:11 caused by: Cannot find control with name: 'det'
我的表单生成器如下:
this.AccForm = this.fb.group({
accid: ['', Validators.required],
accnbr: ['', Validators.required],
cyc: this.fb.group({
cycid:['', Validators.required],
name:['', Validators.required],
description:['', Validators.required],
det: this.fb.group({
dcycid: ['', Validators.required],
status: ['', Validators.required],
})
})
});
在我的模板中,当我尝试获取表单组名时 'det' 我收到了错误消息?
<div formGroupName="det">
<div class="row">
<div class="form-group>
<span><strong>Id</strong></span>
<input formControlName="dcycid" id="dcycid" type="number" class="form-control">
</div>
<div class="form-group">
<span><strong>status</strong></span>
<input formControlName="status" id="status" type="text" class="form-control">
</div>
</div>
</div>
注意 'det' 嵌套在第 3 层。
知道哪里出了问题吗?
谢谢。
/K欧
请找到更正后的 HTML,您需要做的是按照 JSON
嵌套 FormGroupNames
<div [formGroup]="AccForm">
<div formGroupName="cyc">
<div formGroupName="det">
<div class="row">
<div class="form-group">
<span><strong>Id</strong></span>
<input formControlName="dcycid" id="dcycid" type="number" class="form-control">
</div>
<div class="form-group">
<span><strong>status</strong></span>
<input formControlName="status" id="status" type="text" class="form-control">
</div>
</div>
</div>
我遇到以下错误:
EXCEPTION: Uncaught (in promise): Error: Error in ./AccComponent class AccComponent - inline template:106:11 caused by: Cannot find control with name: 'det'
我的表单生成器如下:
this.AccForm = this.fb.group({
accid: ['', Validators.required],
accnbr: ['', Validators.required],
cyc: this.fb.group({
cycid:['', Validators.required],
name:['', Validators.required],
description:['', Validators.required],
det: this.fb.group({
dcycid: ['', Validators.required],
status: ['', Validators.required],
})
})
});
在我的模板中,当我尝试获取表单组名时 'det' 我收到了错误消息?
<div formGroupName="det">
<div class="row">
<div class="form-group>
<span><strong>Id</strong></span>
<input formControlName="dcycid" id="dcycid" type="number" class="form-control">
</div>
<div class="form-group">
<span><strong>status</strong></span>
<input formControlName="status" id="status" type="text" class="form-control">
</div>
</div>
</div>
注意 'det' 嵌套在第 3 层。
知道哪里出了问题吗?
谢谢。
/K欧
请找到更正后的 HTML,您需要做的是按照 JSON
嵌套 FormGroupNames<div [formGroup]="AccForm">
<div formGroupName="cyc">
<div formGroupName="det">
<div class="row">
<div class="form-group">
<span><strong>Id</strong></span>
<input formControlName="dcycid" id="dcycid" type="number" class="form-control">
</div>
<div class="form-group">
<span><strong>status</strong></span>
<input formControlName="status" id="status" type="text" class="form-control">
</div>
</div>
</div>