Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在angular2中访问窗体数组中控件的值_Angular_Typescript - Fatal编程技术网

在angular2中访问窗体数组中控件的值

在angular2中访问窗体数组中控件的值,angular,typescript,Angular,Typescript,我使用RESTAPI结果数组通过FormBuilder设置表单 这是我的表单生成器代码 this._inspectionService.getChecklists(this.truckParam) .subscribe( res=> { this.checklists = res; let inspectionform: FormGroup; let checkinputs: FormArray = new FormArray([]);

我使用RESTAPI结果数组通过FormBuilder设置表单

这是我的表单生成器代码

 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)
      })

    },
  );

哪里出了问题

没有名为“checklists.controls[“noradio”]”的表单控件,它将绑定到
[formControl]=“checklists.controls['noradio']”
,因为这样它就直接附加到控件对象<代码>[formControlName]=“'noradio'”也可以工作,但FormArray访问和控制不是我的强项


两者之间的语法差异很大,足以证明这一点。

您的代码中的inputfileds是否也存在拼写错误,还是仅此而已?无论如何,试试formControlName='{{checklists.controls[“noradio”].value}}}'…它不是inspectionform.controls['''']…不,它在表单生成器上没有错,我实际上把它作为inputfileds,但是用控件访问FormBuilder对象,它被分配给
inspectionform
那么为什么不试试
inspectionform.control['inputfileds]['noradio']
因为您要将它添加到该生成器中。#wesside正在遍历控件数组,从哪个单选按钮开始,我应该使用什么绑定,因为使用formControl绑定会导致两者都被选中。每个HTML单选按钮按
名称分组,然后按其
值区分开来。
:@GEOFFREYMWANGI以获取您的att因为我在第一次评论中忘记了。
<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"]'