Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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
Json 具有多个步骤和嵌套字段的角度表单_Json_Angular_Typescript_Angular Reactive Forms_Angular Formly - Fatal编程技术网

Json 具有多个步骤和嵌套字段的角度表单

Json 具有多个步骤和嵌套字段的角度表单,json,angular,typescript,angular-reactive-forms,angular-formly,Json,Angular,Typescript,Angular Reactive Forms,Angular Formly,我被分配到使用formly构建表单的项目中。它们中的大多数要么是普通的单页表单,要么是来自jsonSchema的表单。我被要求研究带有标签的嵌套表单等 除了不在模型中创建嵌套对象外,它似乎正在工作。我需要这样的东西: { category1: { subcat1: { field1: 'value', field2: 'value' }, subcat2: { field1: 'value',

我被分配到使用formly构建表单的项目中。它们中的大多数要么是普通的单页表单,要么是来自jsonSchema的表单。我被要求研究带有标签的嵌套表单等

除了不在模型中创建嵌套对象外,它似乎正在工作。我需要这样的东西:

{
   category1: {
      subcat1: {
         field1: 'value',
         field2: 'value'
      },
      subcat2: {
         field1: 'value',
         field2: 'value'
      }
   },
   category2: {
   ...
   }
}

您需要添加FormGroup和FormArray,如下所示

  this.FormGroupName = fb.group({
    id: [null],
    //default form controls put here
    CatgoryList1: this.fb.group({
        List1: this.fb.array([
          this.fb.group({
            Field1: [null], //you can apply validation here
            Field2: [null]
          })
        ]),
        //and so on..
    }),
    CatgoryList2: this.fb.group({
        List2: this.fb.array([
          this.fb.group({
            Field3: [null],
            Field4: [null]
          })
        ]),
        //and so on..
    }),
    //and so on..
});  

this.CatList.push(this.initCatListGroup_Cat1());


get CatList() {
    return this.FormGroupName.get('CatgoryList1').get('List1') as FormArray;
}

initCatListGroup_Cat1() {
    return this.fb.group({
      Field1: [null],
      Field2: [null]
    })
}
您还可以按如下方式动态推入表单

  this.FormGroupName = fb.group({
    id: [null],
    //default form controls put here
    CatgoryList1: this.fb.group({
        List1: this.fb.array([
          this.fb.group({
            Field1: [null], //you can apply validation here
            Field2: [null]
          })
        ]),
        //and so on..
    }),
    CatgoryList2: this.fb.group({
        List2: this.fb.array([
          this.fb.group({
            Field3: [null],
            Field4: [null]
          })
        ]),
        //and so on..
    }),
    //and so on..
});  

this.CatList.push(this.initCatListGroup_Cat1());


get CatList() {
    return this.FormGroupName.get('CatgoryList1').get('List1') as FormArray;
}

initCatListGroup_Cat1() {
    return this.fb.group({
      Field1: [null],
      Field2: [null]
    })
}

我希望这对你有帮助。:)

您需要添加FormGroup和FormArray,如下所示

  this.FormGroupName = fb.group({
    id: [null],
    //default form controls put here
    CatgoryList1: this.fb.group({
        List1: this.fb.array([
          this.fb.group({
            Field1: [null], //you can apply validation here
            Field2: [null]
          })
        ]),
        //and so on..
    }),
    CatgoryList2: this.fb.group({
        List2: this.fb.array([
          this.fb.group({
            Field3: [null],
            Field4: [null]
          })
        ]),
        //and so on..
    }),
    //and so on..
});  

this.CatList.push(this.initCatListGroup_Cat1());


get CatList() {
    return this.FormGroupName.get('CatgoryList1').get('List1') as FormArray;
}

initCatListGroup_Cat1() {
    return this.fb.group({
      Field1: [null],
      Field2: [null]
    })
}
您还可以按如下方式动态推入表单

  this.FormGroupName = fb.group({
    id: [null],
    //default form controls put here
    CatgoryList1: this.fb.group({
        List1: this.fb.array([
          this.fb.group({
            Field1: [null], //you can apply validation here
            Field2: [null]
          })
        ]),
        //and so on..
    }),
    CatgoryList2: this.fb.group({
        List2: this.fb.array([
          this.fb.group({
            Field3: [null],
            Field4: [null]
          })
        ]),
        //and so on..
    }),
    //and so on..
});  

this.CatList.push(this.initCatListGroup_Cat1());


get CatList() {
    return this.FormGroupName.get('CatgoryList1').get('List1') as FormArray;
}

initCatListGroup_Cat1() {
    return this.fb.group({
      Field1: [null],
      Field2: [null]
    })
}

我希望这对你有帮助。:)

是的,我也是这样开始的,它似乎在工作,但需要手动构建表单,这破坏了使用表单的想法。我目前正在基于JSON构建这个结构。同时,我使用hideExpression来隐藏不应该显示的子部分,我已经检查过了,我想与您共享这个链接,它是完全定制的。我希望这对你有帮助。:)是的,我也是这样开始的,它似乎在工作,但需要手动构建表单,这破坏了使用表单的想法。我目前正在基于JSON构建这个结构。同时,我使用hideExpression来隐藏不应该显示的子部分,我已经检查过了,我想与您共享这个链接,它是完全定制的。我希望这对你有帮助。:)