I am using a service to get data in JSON format for my table in an Angular 7 project. This is the definition of the service.
getLandingDashboardSnapshotDetails() {
return this.http.get<Snapshot[]>('<removed>');
}
This is the snapshot model used in the service
export interface Snapshot {
RequestsPendingApproval: string,
TotalApprovedRequests: string,
TotalDrafts: string,
TotalRejectedRequests: string
}
In my .ts file, this is what I've defined.
LandingDashboardSnapshotData: Snapshot[];
ngOnInit() {
this.messageService.getLandingDashboardSnapshotDetails().subscribe(
response => {
this.LandingDashboardSnapshotData = response;
console.log(this.LandingDashboardSnapshotData)
},
errorResponse => { console.log(errorResponse) }
);
This is how I'm trying to display the data in my table.
<div class="container">
<table class='reports'>
<tr *ngFor = "let d of LandingDashboardSnapshotData">
<th class="reports-data">Pending for Approval : {{ d.RequestsPendingApproval }} </th>
<th class="reports-data">Total Sent : 11</th>
<th class="reports-data">Total Drafts : 4</th>
<th class="reports-data"> Total Rejected : 4</th>
</tr>
</table>
</div>
I'm able to see the data from the service using console.log(). However, when I try to run this, I get an error saying : Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. I don't understand why I'm getting the error. How else can I display the data?