I have data like this received from the server:
{
7281: [//post id
{
tags: [
{
name: 'name',
link: 'link'
},
{
name: 'name',
link: 'link'
}
]
}
]
}
The postlist.ts file declares a property:
private postlists: Observable<any>;
And the method for getting json:
loadData() {
var
url: string = '...';
this.http.get<any>(url)
.subscribe(
data => {
this.postlists = data;
},
error => {
console.log(error);
}
);
}
In the template file - the output of the received object:
<div sino-item *ngFor="let post of postlists">
<div *ngFor="let data of post">
<div *ngFor="let tag of data.tags">
<p><a href="{{tag.link}}">{{tag.name}}</a></p>
</div>
</div>
</div>
I have an error like this:
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
What am I doing wrong?
I made corrections, but now, when building, ionic throws the following error:
ERROR in src/app/postlist/postlist.page.html:7:78 - error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type 'Observable<any>' is not assignable to parameter of type 'Map<unknown, unknown>'.
Type 'Observable<any>' is missing the following properties from type 'Map<unknown, unknown>': clear, delete, get, has, and 7 more.
7 <div *ngFor="let post of postlists | keyvalue">
~~~~~~~~~
src/app/postlist/postlist.page.ts:8:16
8 templateUrl: './postlist.page.html',
~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component PostlistPage.
[ERROR] An error occurred while running subprocess ng.
data
is the object you show in your question, that's not an array or anything other that provides an iterator. You must pass in something iterable – derpirscher