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"
}
}
}
}