mergeMap函数在Angular 5中给出错误

时间:2018-08-01 06:42:25

标签: angular typescript firebase ionic3

错误:AngularFireObject <{}>无法分配为类型ObservableInput<{}>

enter image description here 这是示例功能代码

getAuthenticatedUserProfile(){

return this.auth.authState
    .map(user => user.uid)
    .mergeMap(authId => this.afDatabase.object('/profile/'+authId))
    .take(1)
}

1 个答案:

答案 0 :(得分:3)

mergeMap期望返回类型为ObservableInput<{}>的值。您正在呼叫this.afDatabase.object('/profile/'+authId),这将返回AngularFireObject<{}>

调用valueChanges()会将其转换为可观察的:

return this.auth.authState
    .map(user => user.uid)
    .mergeMap(authId => this.afDatabase.object('/profile/'+authId).valueChanges())
    .take(1)
}