使用Angular以Json形式检索Firebase实时数据库



我使用Google Script将数据从Google表发送到firebase实时数据库。在这里,我试图检索json形式的这些数据。我的实时数据库看起来像:[![1]][1]我service.ts

getRealData():Observable<any>{
return  this.afs.collection('draft-memorial-default-rtdb')
.snapshotChanges().pipe(
map(item => {
return item.map(value => {
const ref = value.payload.doc.data();
console.log(ref);
return {
ref
};

});
})
);
}

组件:

ngOnInit() {
this.auth.getRealData().subscribe(res=>console.log(res));
}

我已经做了其他数据库,但与实时数据库,我们如何检索数据,如果数据是从谷歌表存储使用谷歌脚本?[1]: https://i.stack.imgur.com/D2Kfv.png

我找到了解决方案:service.ts

getAll(): AngularFireList<any> {
return this.tutorialsRef;
}

组件

ngOnInit() {
this.getRealData();
}
getRealData(): void {
this.auth.getAll().snapshotChanges().pipe(
map(changes =>
changes.map(c =>
({ key: c.payload.key, ...c.payload.val() })
)
)
).subscribe(res => {
this.data = res;
console.log(res);
});
}

返回键值和有效载荷。

最新更新