Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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
Forms 角度4动态形式数组_Forms_Angular_Typescript_Ionic Framework - Fatal编程技术网

Forms 角度4动态形式数组

Forms 角度4动态形式数组,forms,angular,typescript,ionic-framework,Forms,Angular,Typescript,Ionic Framework,我有一个基于angular文档的动态表单,我有一个函数,允许用户加载保存的表单。目前,我可以修补其他表单字段(如textfield和radiobutton)的值,但我不能在数组上进行修补,因为它的值是数组。 我有以下代码 if(value instanceof Array){ value.forEach((subVal, index)=>{ let a = subVal.value this.form.controls[key]

我有一个基于angular文档的动态表单,我有一个函数,允许用户加载保存的表单。目前,我可以修补其他表单字段(如textfield和radiobutton)的值,但我不能在数组上进行修补,因为它的值是数组。 我有以下代码

if(value instanceof Array){
         value.forEach((subVal, index)=>{
           let a = subVal.value
           this.form.controls[key].patchValue({index,a})
         })
          //  
      }else{
      this.form.controls[key].patchValue(value);
      }

我会重新开始制作一个函数并在那里创建表单。保存或创建记录时,应调用函数

如果只想更新一个值,可以使用
.patchValue()

像这样:

createForm(data: any){
  let newFormArray: FormGroup[] = [];
  for(let i = 0; i > data.length; i++){
    newFormArray.push(this.fb.group({
                    id: data[i].id,
                    name: data[i].name
     }));
  }
  this.form = this.fb.group({
       array: this.fb.array(newFormArray)
  })
}

你能分享你的阵列格式吗?你能在stackblitz中复制这个吗