Reputation: 191
I am attempting to display this JSON data from the server:
{"buySell":
[
{"date":"2015-03-02","close":120.351,"buySell":"Sell"},
{"date":"2019-01-02","close":157.2455,"buySell":"Buy"}
],
"firstReturn":0.62987323647548421,
"sell":{"date":"2018-10-08","close":222.0396},
"buy":{"date":"2018-05-02","close":173.9216}
}
This is how I format it in HTML:
<mat-list *ngIf="buySellData$ | async as stock else noData">
<mat-list-item *ngFor="let item of stock ">
{{item.listOfBuySell | json}}
</mat-list-item>
</mat-list>
This is the stock format
stock: Cagr[];
and carg.ts is:
import { Istock } from './istock'
import { Dateclose } from './dateclose'
export class Cagr {
listOfBuySell: Istock;
close: number;
sell: Dateclose;
buy : Dateclose;
}
istock.ts is:
export class Istock {
date: Date;
close: number;
buysell: string;
}
and finally dateclose.ts
export class Dateclose {
date: Date;
close: number;
}
This is the error I get in displaying:
Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
Upvotes: 0
Views: 143
Reputation: 8040
You are trying to iterate over an object but not array. This causes such error.
You should check what exactly you have as a result in buySellData$ | async
.
Upvotes: 1