I am struggling to retrieve data from a JSON file in Object format using Typescript. When I try to fetch the data from the API, it doesn't display as expected.
Typescript
this.http.get('http://example.com/api')
.subscribe((data) => {
console.log(data);
});
The structure of the API JSON file is as follows:
{
1: {id:1, name: "string"}
2: {id:1, name: "string"}
3: {id:1, name: "string"}
4: {id:1, name: "string"}
}
I need help with looping through this data later on.
<ion-item *ngFor="let item of data" >
<div>
{{item.name}}
</div>
</ion-item>
Any assistance would be greatly appreciated.
I found a solution to my issue:
<ion-item *ngFor="let item of data | keyvalue" >
<div>
{{ item.key }} {{ item.value['data'] }}
</div>
</ion-item>