The error I get:
core.js:6260 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
at NgForOf.ngDoCheck (common.js:4406)
at callHook (core.js:4762)
at callHooks (core.js:4722)
at executeCheckHooks (core.js:4642)
at refreshView (core.js:11979)
at refreshComponent (core.js:13449)
at refreshChildComponents (core.js:11689)
at refreshView (core.js:12024)
at refreshComponent (core.js:13449)
at refreshChildComponents (core.js:11689)
The code below works if I have more then one object. When the data is as shown below, and from that, I understand that something is wrong with array or object but I am unable to figure it out. So when I have 2 objects I get the data in the dropdown, but when it is one I get the error mentioned above.
[
{..},
{..}
]
My data Looks like this:
{
"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
}
My http get request code is as below:
this.http.get(this.apiBaseUrl+"ProgramDets/"+id).toPromise().then(res => this.Details = res as TrDetails);
My model code:
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;
}
My service code:
apiBaseUrl = "http://localhost:2676/api/";
Details : TrainingDetails;
GetDetails(id){
this.http.get(this.apiBaseUrl+"ProgramDets/"+id).toPromise().then(res =>
this.Details = res as TrDetails);
}
My dropdown code:
<option *ngFor="let data of service.Details" [value]="data.start_date">{{data.program_start_date}}</option>