在嵌套中构建Angular动态表单

时间:2018-11-01 08:11:02

标签: javascript angular typescript angular-reactive-forms angular-forms

我正在使用 Angular动态表单,并通过链接https://angular.io/guide/dynamic-form

来创建angular 6应用程序

我需要以嵌套格式显示表单...

场景1

//填写项目名称和描述

最初,会有两个文本框,分别是项目名称和描述,

let questions: QuestionBase<any>[] = [
  new TextboxQuestion({
    key: 'project_name',
    label: 'Project name',
    required: true,
    type: 'text',
    order: 1
  }),

  new TextboxQuestion({
    key: 'description',
    label: 'Description',
    type: 'text',
    order: 2
  })
];

填写两个字段后,用户将单击此表单底部的添加。

场景2

//点击添加其他表单

点击添加后,另一个表单的输入为

let questions: QuestionBase<any>[] = [
  new TextboxQuestion({
    key: 'property_one',
    label: 'Property One',
    required: true,
    type: 'text',
    order: 1
  }),

  new TextboxQuestion({
    key: 'property_two',
    label: 'Property Two',
    type: 'text',
    order: 2
  }),

  new DropdownQuestion({
    key: 'level',
    label: 'Priority Level',
    options: [
      { key: 'low', value: 'Low' },
      { key: 'medium', value: 'Medium' },
      { key: 'high', value: 'High' },
    ],
    order: 3
  }),
];

需要显示。

填写完两个表格并单击“保存”后,需要存储所有数据。

我的工作示例https://stackblitz.com/edit/angular-ysy2xa

我正在制作两种形式,但它占用了最后生成的形式。我知道这是错误的方法,因为我是角动态形式的新手,请在填写前两个输入字段(项目名称和描述)后单击添加,以帮助我实现生成新形式(带有属性)的结果)...

0 个答案:

没有答案
相关问题