0

服务器响应后,我需要更新每个表单组内的输入值

TS

    initAddressRows() {
                return this._fb.group({

                    lat: 0,
                    lon: 0,
                    maxTravelTime: this.maxTime[0],


                });
           }

bindDATA(index) {    
this.service.getData().subscribe(
                      (response) => {this.actualData = response.json()

                                     this.lon = this.actualData.x;
                                     this.lat = this.actualData.y;
                                // UPDATE THERE 'lat' and 'lon' inputs
                       },
                      (error) => console.log('ERROR: ' + error)
              ); 
}

形式.价值

 "addresses": [
    {
      "lat": 0,
      "lon": 0,
      "maxTravelTime": "5 min",
    },
    {

      "lat": 0,
      "lon": 0,
      "maxTravelTime": "5 min",
    },
    {

      "lat": 0,
      "lon": 0,
      "maxTravelTime": "5 min",
    }
  ]

html

<div class="row" *ngFor="let itemrow of form.controls.addresses.controls; let ind=index" [formGroupName]="ind">
          ...
            <select>
            <option  (onSelectionChange)="bindDATA(ind)" *ngFor="let option of testLocation; let in=index" [value]="option">
                {{ option.text }}
            <option>
            </select>
            ...
            </div>
4

0 回答 0