我在使用Angular HTTP get方法检索blogger.com JSON数据时遇到了困难。
如果我使用this.posts = data;
,我会收到Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
错误,当我使用this.posts = Array.of(data)
时,响应位于Array of Array内,并且不显示任何输出。
jsonApiProvider.myBlogger(1)
.map(res => res.json().items)
.subscribe(data => {
this.posts = Array.of(data);
console.log(this.posts)
}, err => console.error(err)
);
以下是最终回复的屏幕截图。 json response screenshot
this.posts = data; console.log(this.posts)
的回复:this.posts = data response
ngFor循环:
<ion-card *ngFor="let post of posts">
<ion-item *ngFor="let author of post.author">
<ion-avatar item-left>
<img src="{{author.image.url}}" />
</ion-avatar>
<h2>{{author.displayName}}</h2>
<p>{{post.published | date:'dd/MM/yyyy'}}</p>
</ion-item>
<div *ngFor="let thumbnail of post.images">
<img src="{{thumbnail.url}}" />
</div>
<ion-card-content>
<ion-card-title>{{post.title}}</ion-card-title>
<div [innerHTML]="post.content">
{{post.content}}
</div>
</ion-card-content>
</ion-card>
如何在Angular(Ionic)中迭代JSON对象?我的方法不对吗?