【发布时间】:2018-03-20 12:30:19
【问题描述】:
我已使用该功能将 img URL 上传到我的数据库:
private saveFileData(upload: Upload): void {
this.firebaseAuth.authState.subscribe(auth => {
this.db.list(`uploads/${auth && auth.email && auth.uid}`).push(upload);
})
}
之后我想用那个函数来获取它,第一个是路径引用,因为我只希望登录的用户会看到他们自己上传的内容 :
this.firebaseAuth.authState.subscribe(auth => {
if(auth && auth.email && auth.uid) {
this.uploadRef = this.db.list<any>(`uploads/${auth && auth.email && auth.uid}`);
console.log("Gaunami profilio duomenys")
}
else {
console.log("Nerandama img")
}
})
最后我想获得上传的图片列表:
get getListUploads(): Observable<AngularFireAction<DatabaseSnapshot>[]> {
return this.uploadRef.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
}
我在控制台中遇到错误:
ERROR TypeError: Cannot read property 'snapshotChanges' of undefined
at UploadService.get [as getListUploads] (upload.service.ts:30)
上传工作正常,我在我的数据库中看到照片名称和网址,我在存储中看到照片,但无法从那里获取。有什么建议吗?
【问题讨论】:
-
你的 getListUploads getter 在哪里使用?您能否将 upload.service.ts 添加到您的问题中?
标签: angular typescript firebase firebase-realtime-database firebase-authentication