formGroup中的Angular2补丁输入值

时间:2017-12-07 12:50:48

标签: forms angular formgroups

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

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)
              ); 
}

form.value

 "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>

0 个答案:

没有答案