【发布时间】:2018-10-23 07:19:18
【问题描述】:
我有以下html:
<form [formGroup]="customFieldForm">
..........
<div formArrayName="FieldNames">
<div *ngFor="let fieldName of customFieldForm.get('FieldNames').controls; let i = index"
[formGroupName]="i">
<mat-form-field>
<input matInput [value]="fieldName.value.CustomFieldName"
[formControlName]="CustomFieldName"
[placeholder]="placeHolderInLocalLanguage">
</mat-form-field>
</div>
</form
我收到以下错误:
Cannot find control with path: 'FieldNames -> 0 (and all the length of the array...) ->
TS 文件:
this.customFieldForm = new FormGroup({
Menu: new FormControl(null, Validators.required),
FieldType: new FormControl(null, Validators.required),
FieldNames : new FormArray([]),
OptionalOrMendatory: new FormControl(false),
LineTypes: new FormControl(null),
})
从服务器发起数据:
this.data.forEach(nameAndLanguage => {
const FieldName: FormGroup = this.fb.group({
CustomFieldName: nameAndLanguage.CustomFieldName,
ID: nameAndLanguage.LanguageID
});
(<FormArray>this.customFieldForm.get('FieldNames')).push(FieldName);
})
任何人都可以在这里发现我做错了什么?
感谢任何试图提前提供帮助的人!
【问题讨论】:
-
试试
<div formArrayName="FieldNames" *ngIf="ustomFieldForm.get('FieldNames').controls"></div> -
不幸的是,这似乎不是问题:(但谢谢!
标签: javascript html angular forms