我无法使用NgFor在离子视图中显示数组
this.dbFire.database.ref('found').orderByChild('author_email').equalTo(this.email).once('value')
.then(snapshot => snapshot.val())
.then((data) => {
// push data
this.getUserPosts.push(data);
console.log(this.getUserPosts);
});
View:
<ion-col *ngFor="let posts of getUserPosts">
<p>{{posts.post_name}}</p>
<p></p>
</ion-col>
答案 0 :(得分:0)
根据getUserPosts
的结构,您应该执行以下操作:
添加新的类成员postids
作为字符串数组。代码修改如下:
this.dbFire.database.ref('found').orderByChild('author_email').equalTo(this.email).once('value')
.then(snapshot =>
snapshot.val())
.then((data) => {
// push data
this.getUserPosts.push(data);
console.log(this.getUserPosts);
this.postids = Object.keys(this.getUserPosts[0]);
console.log(this.postids);
});
查看:
<ion-col *ngFor="let postid of postids">
<p>{{ getUserPosts[0][postid].post_name}}</p>
<p></p>
</ion-col>