【发布时间】:2020-09-18 14:26:18
【问题描述】:
我得到的错误:
core.js:6260 ERROR 错误:找不到“object”类型的不同支持对象“[object Object]”。 NgFor 只支持绑定到 Arrays 等 Iterables。
在 NgForOf.ngDoCheck (common.js:4406)
在 callHook (core.js:4762)
在 callHooks (core.js:4722)
在 executeCheckHooks (core.js:4642)
在 refreshView (core.js:11979)
在 refreshComponent (core.js:13449)
在 refreshChildComponents (core.js:11689)
在 refreshView (core.js:12024)
在 refreshComponent (core.js:13449)
在 refreshChildComponents (core.js:11689)
如果我有多个对象,则下面的代码有效。当数据如下所示时,我知道数组或对象有问题,但我无法弄清楚。因此,当我有 2 个对象时,我会在下拉列表中获取数据,但是当它是一个对象时,我会收到上述错误。
[
{..},
{..}
]
我的数据如下所示:
{
"details_id": 218,
"master_code": 218,
"MstCode": null,
"start_date": "2020-02-29T00:00:00",
"end_date": "2020-02-29T00:00:00",
"canceled": "False ",
"data_archived": null,
"last_updated_on": "2020-02-28 11:37:08",
"last_updated_by": null
}
我的http get请求代码如下:
this.http.get(this.apiBaseUrl+"ProgramDets/"+id).toPromise().then(res => this.Details = res as TrDetails);
我的型号代码:
export class TrDetails {
details_id: number;
master_code: number;
MstCode: number;
start_date: Date;
end_date: Date;
canceled: string;
data_archived: string;
last_updated_on: Date;
last_updated_by: string;
}
我的服务代码:
apiBaseUrl = "http://localhost:2676/api/";
Details : TrainingDetails;
GetDetails(id){
this.http.get(this.apiBaseUrl+"ProgramDets/"+id).toPromise().then(res =>
this.Details = res as TrDetails);
}
我的下拉代码:
<option *ngFor="let data of service.Details" [value]="data.start_date">{{data.program_start_date}}</option>
【问题讨论】:
-
你能不能显示你在 then 方法中
console.log(res)时得到了什么以及你在哪里使用GetDetails方法 -
data_archived: null canceled: "False " last_updated_by: null last_updated_on: "2020-02-28 11:31:58" end_date: "2020-02-29T00:00:00" start_date: "2020-02-29T00:00:00" MstCode: null details_id: 217 master_code: 1 -
你在哪里使用
GetDetails方法? -
在我的组件 TypeScript 文件中
-
并且你的下拉代码属于组件 html 对