更新AngularFire2对象时出错

更新AngularFire2对象时出错,angular,typescript,angularfire2,Angular,Typescript,Angularfire2,我正在使用AngularFire2检索Firebase对象: // AuthService public getUserID (): Observable<string> { return this.afAuth.authState.map(user => user ? user.uid : null) } // AccountService private profileInfo: FirebaseObjectObservable<any> constr

我正在使用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
}

当函数执行时,我收到一个运行时错误:
TypeError:this.profileInfo.update不是函数
。我做错了什么?

我通过在地图中手动分配它来实现这一点:

this.profileInfo = authService.getUserID().flatMap(uid => {
    const profileInfo = db.object(`Users/${uid}`)
    this.profileInfo = profileInfo
    return profileInfo
}) as FirebaseObjectObservable<any>
this.profileInfo=authService.getUserID().flatMap(uid=>{
const profileInfo=db.object(`Users/${uid}`)
this.profileInfo=profileInfo
返回配置文件信息
})可观察到的
我对这个解决方案不满意,它感觉真的有点黑客味,但至少它是有效的

更新:进一步测试后,如果您注销并重新登录,结果会抛出一个错误,因为它丢失了对uid的引用。我在解决问题方面的最佳尝试甚至更加丑陋:

this.profileInfo = authService.getUserID().flatMap(uid => {
    const profileInfo = db.object(`Users/${uid}`)
    this.profileInfo.$ref = profileInfo.$ref
    this.profileInfo.update = profileInfo.update
    return profileInfo
}) as FirebaseObjectObservable<any>
this.profileInfo=authService.getUserID().flatMap(uid=>{
const profileInfo=db.object(`Users/${uid}`)
this.profileInfo.$ref=profileInfo.$ref
this.profileInfo.update=profileInfo.update
返回配置文件信息
})可观察到的
(如果要使用任何其他方法,还需要单独添加它们)

this.profileInfo = authService.getUserID().flatMap(uid => {
    const profileInfo = db.object(`Users/${uid}`)
    this.profileInfo.$ref = profileInfo.$ref
    this.profileInfo.update = profileInfo.update
    return profileInfo
}) as FirebaseObjectObservable<any>