[英]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.