【问题标题】:Error showing data from firebase to ionic显示从 firebase 到 ionic 的数据时出错
【发布时间】:2018-08-15 19:53:44
【问题描述】:

我想显示来自这个 console.log 的数据,但我遇到了错误。

错误是:错误:找不到“object”类型的不同支持对象“[object Object]”。 NgFor 只支持绑定到 Arrays 等 Iterables。

这是代码的一部分:

this.dbFire.database.ref('found').orderByChild('author_email')
            .equalTo(this.email)
            .once('value')
            .then(snapshot => snapshot.val())
            .then((data) => {
                this.getUserPosts = data;

                console.log(this.getUserPosts);
            });

谢谢!

【问题讨论】:

  • 兄弟你得到的是一个对象..如果你想使用 *NgFor 使它成为一个数组
  • 我该怎么做?谢谢兄弟!
  • 您使用的是哪个版本的 Angular..?
  • 离子版本:3.20.0

标签: javascript firebase ionic-framework


【解决方案1】:
// declare variable as empty array
getUserPosts: any[] = [];

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);
    });

<li * ngFor="let user of getUserPosts" >
    {{ user.author_email}}
</li>

【讨论】:

  • 谢谢你,爱迪生!现在它是数组,但我无法显示。新的控制台日志:link
猜你喜欢
  • 2018-06-17
  • 2018-10-12
  • 2023-03-11
  • 2021-06-03
  • 2020-04-29
  • 1970-01-01
  • 2021-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多