我得到一个FormBuilder
阵列的formControlName
得到一个错误:无法获得FormBuilder阵列的formControlName
Error: Cannot find control with path: 'elements -> 0 -> name'
<form [formGroup]="targetAttributesForm" (ngSubmit)="save(myForm)">
<input formControlName="nono" placeholder="First">
<div formArrayName="elements">
<div *ngFor="let address of targetAttributesForm.controls.elements.controls; let w=index" class="panel panel-default">
<div [formGroupName]="w">
<span>Att {{w + 1}}</span>
--> {{ address[w] }}
<label>Attribut name</label><input type="text" formControlName="name">
<label>Attribut type</label>
</div>
</div>
</div>
</form>
我app.component.ts:
ngOnInit() {
this.targetAttributesForm = this._fb.group({
nono : ['a', Validators.required],
elements : this._fb.array([this.initAttribut])
});
}
initAttribut() {
return this._fb.group({
name : ['a', [Validators.required]],
type : ['b', Validators.required]
});
}
这是我的错误:
Error: Cannot find control with path: 'elements -> 0 -> name' Trace de la pile : [email protected]http://localhost:4200/vendor.bundle.js:69949:11 [email protected]http://localhost:4200/vendor.bundle.js:69857:9 ../../..
欢迎StackOverflow上。请阅读[问](https://stackoverflow.com/help/asking)和[我如何问一个好问题](https://stackoverflow.com/help/how-to-ask)。我纠正了你的问题:我简化了标题(尽可能简洁!);我使用了所有错误消息的blockquotes;我还重写了句子,删除了所有无用的部分(例如“请帮助我!”或多个问题/询问标记)。 –
manu谢谢Massimiliano –