当对象值更改时,选择选项列表不会更新

时间:2017-11-10 10:52:34

标签: angular

我正在尝试在上传文件时更新下拉列表。在控制台中,我可以看到正在显示的对象数据。但它没有更新下拉列表。我正在使用formControlName属性来绑定对象数据。

HTML

<select formControlName="fileInfoObj" class="form-control" disabled>
  <option *ngFor="let worksheet of fileInfoObj.worksheets" value="worksheet.name">{{worksheet.name}}</option>
</select>

TS

    private fileInfoObj: Object = {};
    ngOnInit(): void {
      this.devRequestService.getListOfAgencies().subscribe((data) => {
       ...
       this.uploader.onCompleteItem = (item: any, response: any, status: any, headers:any)=>  {
            console.log(response);
            return this.fileInfoObj = response;
          };
      });
    }

对象

    {
      "key": "[key]",
      "worksheets": [
        {
          "index": 0,
          "name": "default",
          "columns": [
            {
              "index": 0,
              "name": "col-1"
            },
            {
              "index": 1,
              "name": "col-2"
            },
            {
              "index": 2,
              "name": "col-3"
            },
            {
              "index": 3,
              "name": "col-4"
            },
            ...
          ]
        }
      ]
    }

1 个答案:

答案 0 :(得分:0)

我必须解析对象的JSON响应才能使其正常工作。

this.fileInfoObj = JSON.parse(response);

从html中删除formControlName

formControlName="fileInfoObj"