简体   繁体   English

如何使用 API 响应数据制作 Angular 响应式(动态)表单? 需要建议

[英]How to make Angular Reactive (Dynamic) form with API Response data? Need advise

[
  {
    "name": "jkjk",
    "firstName": "hgh",
    "lastName": "ehtrh",
    "replytype": "svdv",
    "prodCode": "svv",
    "executor": "ewwe",
    "skills": [
      {},
      {}
    ]
  },
  {
    "name": "sdkjbdsf",
    "firstName": "kdvbfd",
    "lastName": "dkbd",
    "replytype": "SQLServer",
    "prodCode": "vsdv",
    "executor": "vkjbndsf,vd",
    "skills": [
      {
        "name1": "abs"
      },
      {
        "name2": "bbs"
      }
    ]
  }
]

In this case I recommend you to use a *ngFor loop and generate your inputs.在这种情况下,我建议您使用*ngFor循环并生成您的输入。

Add keys as the name property and the values as value.将键添加为name属性,将值添加为值。

Then you can post the data as the usual way back.然后您可以像往常一样发布数据。

<form>
  <div *ngFor="let item of array">
    <ng-container *ngFor="let i of item | keyvalue">
      <input [name]=i.key [value]="i.value" />
    </ng-container>
  </div>
  <button type="submit" (click)="edit()"></button>
</form>
  • Use some conditional tags to provide other types of form tags (select, textarea, ...).使用一些条件标签来提供其他类型的表单标签(select、textarea、...)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM