我正在尝试在上传文件时更新下拉列表。在控制台中,我可以看到正在显示的对象数据。但它没有更新下拉列表。我正在使用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"
},
...
]
}
]
}
答案 0 :(得分:0)
我必须解析对象的JSON响应才能使其正常工作。
this.fileInfoObj = JSON.parse(response);
从html中删除formControlName
:
formControlName="fileInfoObj"