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
, чтобы убедиться, что только пользователи могут читать и записывать данные. Я получаю ошибку
свойство 'map' не существует для типа '{}'
Полный код:
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"
}
}
}
}