【发布时间】:2018-03-06 19:02:05
【问题描述】:
我在获取 formControlName 的 FormBuilder 数组时出错:
错误:找不到带有路径的控件:'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]
});
}
这是我的错误:
错误:找不到带有路径的控件:'元素 -> 0 -> 名称' 追踪 de la pile : _throwError@http://localhost:4200/vendor.bundle.js:69949:11 设置控制@http://localhost:4200/vendor.bundle.js:69857:9 ../../..
【问题讨论】:
-
欢迎来到 StackOverflow。请阅读Asking 和How do I ask a good question。我更正了您的问题:我简化了标题(尽可能简洁!);我对所有错误消息都使用了块引号;我还重写了你的句子,删除了所有无用的部分(例如“请帮助我!”,或多个问号/问号)。
-
manu 感谢马西米利亚诺
标签: angular angular2-forms angular2-formbuilder