【发布时间】:2017-06-30 17:23:54
【问题描述】:
我正在使用 AngularFire2 检索 Firebase 对象:
// AuthService
public getUserID (): Observable<string> {
return this.afAuth.authState.map(user => user ? user.uid : null)
}
// AccountService
private profileInfo: FirebaseObjectObservable<any>
constructor (private db: AngularFireDatabase, private authService: AuthService) {
this.profileInfo = authService.getUserID().flatMap(uid => {
return db.object(`Users/${uid}`)
}) as FirebaseObjectObservable<any>
// have to explicitly cast it or the compiler complains
// not sure if that's related
}
这一切似乎工作正常,我可以从中读取正确的数据,但是当我尝试更新它时:
public changeProfileInfo (name: string) {
this.profileInfo.update({name: name})
}
函数执行时出现运行时错误:TypeError: this.profileInfo.update is not a function。我在这里做错了什么?
【问题讨论】:
标签: angular typescript angularfire2