Angular 嵌套表单数组的角度值

Angular 嵌套表单数组的角度值,angular,nativescript,Angular,Nativescript,我有一个带有多个嵌套表单数组的被动表单。 在我的表单中,我可以有多个段和多个集合,问题是在从数据库获取数据时,使用patchValue()或setValue()编辑我的表单。我知道我需要创建多个表单组来修补这些值,是否有一种方法可以动态创建表单以匹配从数据库接收的数据 ngOnInit() { this.myForm = this.fb.group({ id: '', name: '', userId: "", descr

我有一个带有多个嵌套表单数组的被动表单。 在我的表单中,我可以有多个段和多个集合,问题是在从数据库获取数据时,使用patchValue()或setValue()编辑我的表单。我知道我需要创建多个表单组来修补这些值,是否有一种方法可以动态创建表单以匹配从数据库接收的数据

ngOnInit() {
      this.myForm = this.fb.group({ 
        id: '', 
       name: '',
       userId: "",
       description:'',
       date: "",

      segments: this.fb.array([
         this.fb.group({
           id:'',
           workoutId:'',
           name:'',
           notes: '',
           exerciseName:'',

       sets: this.fb.array([
             this.fb.group({
               id:'',
               segmentId:'',
               name:'',
               reps:'',
               weight:'',
               type:'',
               success:'',
             }),
        ])
     })
   ])
 });
    this.workoutService.getWorkout(this.workoutId).subscribe(
      (Workout) => { this.workout = Workout, this.setValueForm()},
      (err) => console.log(err, "This did not load properlu make a toasty"),
    ) 
}

试着这样做:

let segments = res.segments // value from db

const formArray = new FormArray([]);

segments.forEach(s => {
  formArray.push(this.fb.group({
    id: s.id,
    name: s.name
  }));
});


this.myForm.setControl('segments',formArray);

如果contorll包含嵌套的表单数组l,那么相同的techl是否有效
let segments = res.segments // value from db

const formArray = new FormArray([]);

segments.forEach(s => {
  formArray.push(this.fb.group({
    id: s.id,
    name: s.name
  }));
});


this.myForm.setControl('segments',formArray);