I have an object in our server that is like this;
{
"NBA": {
"link": "https://www.nba.com/",
"ticketPrice": 50
},
"UEFA": {
"link": "https://www.uefa.com/",
"ticketPrice": 39
},
"CL": {
"link": "https://www.uefa.com/uefachampionsleague/",
"ticketPrice": 76
},
"EuroLeague": {
"link": "https://www.euroleague.net/",
"ticketPrice": 42
}
}
I subscribe this object with this piece of code;
sportsObject : Sports[] //THIS IS THE MEMBER THAT SHOULD BE FILLED WITH THE JSON OBJECT GIVEN
object = Object;
ngOnInit(){
this.SportsService.getPrices().subscribe(data=>{
this.sportsObject = data;
})
}
And here is my html code;
<div *ngFor="let key of Object.keys(sportsObject)">
<p>The {{key}} is {{{{sportsObject[key]}}</p>
</div>
But I get the "Cannot find a differ supporting object '[object Object]' of type 'object'." error. How can I properly iterate this JSON object?
*ngForonly accepts arrays. You need to convert your object to iterable array.{ "sports": [ "NBA": {...}, "UEFA": {...} ... ] }so that the service actually returns an array.