I am looking to save the response data from an API call in a variable and display it in the component.html file.
Component.ts file :
public coinsHistory = [];
this.service.getCoinsHistory().subscribe(
(response) => {
this.handleCoinsResponse(response);
},
(error) => {
console.log(error);
}
);
handleCoinsResponse(response: any) {
console.log('what ------', response);
this.spinner.show();
if (response.status === 1) {
this.coinsHistory = response.responseData.data;
console.log(' this.coinsHistory ------', typeof(this.coinsHistory));
}
}
and in component.html file:
<div *ngFor="let coinData of coinsHistory">
<p>{{ coinData.coins_earned_for }}</p>
<p>{{ coinData.referral_coins }}</p>
</div>
Data from api is like this:
status: 1
msgCode: 224
msg: "Referrer coins history"
responseData:
total_coins: 200
data: Array(2)
0:
id: 85
referrer_id: 4
referee_id: null
coins_earned_for: "Deducted for withdraw"
referral_coins: "-100"
created_at: "2020-02-01 12:18:21"
updated_at: "2020-02-01 12:18:21"
1:
id: 85
referrer_id: 4
referee_id: null
coins_earned_for: "Deducted for withdraw"
referral_coins: "-100"
created_at: "2020-02-01 12:18:21"
updated_at: "2020-02-01 12:18:21"
But I encountered an error stating:
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.