[英]Accessing the value of a control in a form array in angular2
我正在通过表单构建器设置我的表单,其中包含一个其余的 api 结果数组
这是我的表单构建器代码
this._inspectionService.getChecklists(this.truckParam)
.subscribe(
res=> {
this.checklists = res;
let inspectionform: FormGroup;
let checkinputs: FormArray = new FormArray([]);
for (let i = 0; i < this.checklists.length; i++) {
checkinputs.push(
new FormGroup({
description:new FormControl(this.checklists[i].item),
input: new FormControl(''),
yesradio: new FormControl(''),
noradio: new FormControl(''),
})
)
}
this.inspectionform = this._formBuilder.group({
inputfileds: this._formBuilder.array(checkinputs.controls)
})
},
);
现在以我的形式
<form [formGroup]="inspectionform">
<ion-card *ngFor='let checklists of inspectionform.controls["inputfileds"]["controls"]
;let i=index'>
//at this stage i can access
{{checklists.controls["description"].value}} //it retuns a value
//NOW AM trying to connect the form control inputs via
<ion-input type="text" formControlName='checklists.controls["noradio"]'>
IVE ALSO TRIED
<ion-input type="text" formControlName='checklists.controls.noradio'>
返回的错误是
Cannot find control with name: 'checklists.controls["noradio"]'
我哪里错了
没有名称为 "checklists.controls["noradio"]" 的表单控件,它将与[formControl]="checklists.controls['noradio']"
绑定,但是因为它直接附加到控件对象。 [formControlName]="'noradio'"
也可能有效,但 FormArray 访问和控制不是我的强项。
两者之间的语法完全不同,值得进一步阅读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.