I hope you people can help me. Our plan is to show data saved in a .json file with a ngFor loop.
With my code so far I always get stuck with following error:
Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
I've researched and know that I have to use Pipes to fix it. But i have no clue how it works as I'm quite new to Angular.
This is how I load the JSON and asign it to the temp variable:
ngOnInit(): void {
this.http.get('assets/tempdata.json').subscribe(data => {
//console.log(data);
this.temps = data;
});
}
And here the part of the .html file i want to show it:
<mat-card-content>
<mat-list>
<mat-list-item *ngFor="let temp of temps">
<i class="{{temp.icon}}"></i><p>{{temp.temp}}{{temp.room}}</p>
</mat-list-item>
</mat-list>
</mat-card-content>
And this is the .JSON File I want to display:
{
"temperature": [
{
"temp": "4°",
"room": " Outside",
"icon": 4
},
{
"temp": "21°",
"room": " Livingroom",
"icon": 21
},
{
"temp": "24°",
"room": " Bedroom",
"icon": 24
},
{
"temp": "11°",
"room": " Basement",
"icon": 11
}
]
}
It would be awesome if anybody could help me with this. Any hint or more is helpful. Thanks a lot!