无法从Firebase检索数据

时间:2019-01-19 05:49:35

标签: firebase firebase-realtime-database ionic3

this.itemsRef = this.db.list(`report/`);
this.items = this.itemsRef.snapshotChanges().pipe(
                  map(changes => 
                    changes.map(c => ({ key: c.payload.key, ...c.payload.val() }))
                  )
                );

我正在尝试从Firebase数据库中检索数据,但是问题是当我在onAuthStateChanged内使用上面的代码来确保只有用户可以读写数据时才会出现错误

  

类型“ {}”上不存在属性“地图”

完整代码:

 getpost (){

        this.fire.auth.onAuthStateChanged(function(user) {
              if (user) {
                this.userId = user.uid
                console.log(user)
                this.itemsRef = this.db.list(`report/`);
                this.items = this.itemsRef.snapshotChanges().pipe(
                  map(changes => 
                    changes.map(c => ({ key: c.payload.key, ...c.payload.val() }))
                  )

                );

              } else {
                // No user is signed in.
              }
            });
    }

 ionViewWillLoad(){

      this.getpost()
      }

规则数据库

{
    "rules": {
        "users": {
            "$uid": {
                ".write": "auth.uid === $uid"
            }
        }
    }
}

0 个答案:

没有答案