无法将阵列显示为离子

时间:2018-08-15 12:24:19

标签: firebase ionic-framework

我无法使用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>

console.log

1 个答案:

答案 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>