简体   繁体   中英

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.

Add keys as the name property and the values as value.

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, ...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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