【问题标题】:Update select dynamically with API response data使用 API 响应数据动态更新选择
【发布时间】:2019-11-19 21:01:41
【问题描述】:

我无法使用来自 ngfileupload 的 API 响应(上传的文件中的工作表名称)进行更新选择(下拉菜单)。我可以在浏览器中返回的内容中看到工作表名称,但无法将其动态“放入”选择下拉列表中。

this.uploader.onSuccessItem=(item,response,status,headers)=>
{
  if (response)
  {
    const res:UploadDataStep1=JSON.parse(response);
    const returnDataStep1=
    {
      Url:res.Url,
      SheetNames:res.SheetNames
    };
    console.log(returnDataStep1.Url);
    // this.sheetNames=returnDataStep1.SheetNames;
    this.makeTenderStep1_Form.controls['sheetNames'].patchValue(returnDataStep1.SheetNames);
    //Input here what needs to happen with data
  }
}

和 HTML:

<select class="browser-default custom-select"

          [ngClass]="{'is-invalid':makeTenderStep1_Form.get('sheetNames').errors&&
          makeTenderStep1_Form.get('sheetNames').touched}"
          formControlName="sheetNames" id="sheetNames">
            <option *ngFor="let name of sheetNames; let i = index" [value]="sheetNames[i]">
              {{name}}
            </option>
          </select>
          <ng-template #loading>Awaiting data from uploaded file...</ng-template>
          <!-- <span class="form-text text-muted">Please choose which sheet contains the relevant data (Mandatory)</span> -->
          <div class="invalid-feedback">You need to select a sheet before continuing</div>
          <div class="kt-heading kt-heading--md mt-3">c. Categorise data from file</div>

【问题讨论】:

    标签: angular8 ng-file-upload


    【解决方案1】:

    发现这是一个 put 请求,因此无法明确使用 API 的返回/响应(您实际上可以使用 Params,但那是另一天的讨论)。将其改为获取请求,这使我能够以我想要的方式处理返回数据。

    【讨论】:

      猜你喜欢
      • 2015-07-17
      • 2019-06-15
      • 1970-01-01
      • 2015-07-13
      • 2012-12-20
      • 1970-01-01
      • 2013-01-25
      • 2015-04-11
      • 2017-09-20
      相关资源
      最近更新 更多