嗨,我是新来的有角度的人,目前我遇到如下错误。如果您能对此有所了解,请多谢帮助。
GlobalSettingsComponent.html:66 ERROR Error: Cannot find control with path: 'tagonSettings -> tagonSettingFormGroup -> tagonType'
at _throwError (forms.js:2432)
at setUpControl (forms.js:2300)
at FormGroupDirective.addControl (forms.js:6664)
at FormControlName._setUpControl (forms.js:7314)
at FormControlName.ngOnChanges (forms.js:7227)
at checkAndUpdateDirectiveInline (core.js:12348)
at checkAndUpdateNodeInline (core.js:13876)
at checkAndUpdateNode (core.js:13819)
at debugCheckAndUpdateNode (core.js:14712)
at debugCheckDirectivesFn (core.js:14653)
因此,以下是我正在尝试做的事情。我有一个表单组,并且其中包含表单数组,如下所示:
this.formGroup = this.fb.group({
inventories: this.fb.array([]),
flightRates: this.fb.array([]),
settings: this.fb.array([]),
tagonSettings: this.fb.array([])
});
我尝试在tagonSettings表单数组中如下创建并推送FormGroup的实例。之所以我推动一个表单组是因为我需要对一些控件进行分组。
this.globalTagonSettingsArray.push(
new FormGroup({
id : new FormControl( globalTagonSetting.id ),
tagonText: new FormControl(globalTagonSetting.tagonText, [Validators.required] ),
tagonType: new FormControl(globalTagonSetting.tagonType, [Validators.required] )
}
)
);
在我的组件html中,我正在执行以下操作。
<div class="form-title mb-3 mt-3">{{ 'HEADINGS.ADDITIONAL_TAGON_SETTINGS' | translate }}</div>
<div formArrayName="tagonSettings">
<div class="row" *ngFor="let tagonSettingFormGroup of globalTagonSettingsArray.controls; let i = index">
<div formGroupName="tagonSettingFormGroup">
<div class="col-4">
<input formControlName="tagonText">
</div>
<div class="col-4">
<input formControlName="tagonType">
</div>
<div class="col-4"></div>
</div>
</div>
</div>
答案 0 :(得分:0)
我应该已经添加了formGroup] =“ tagonSettingFormGroup”。现在它开始工作了。
<div class="form-title mb-3 mt-3">{{ 'HEADINGS.ADDITIONAL_TAGON_SETTINGS' | translate }}</div>
<div formArrayName="tagonSettings">
<div class="row" *ngFor="let tagonSettingFormGroup of globalTagonSettingsArray.controls; let i = index">
<div [formGroup]="tagonSettingFormGroup" >
<div class="col-4">
<input formControlName="tagonText">
</div>
<div class="col-4">
<input formControlName="tagonType">
</div>
<div class="col-4"></div>
</div>
</div>
</div>