0
我想用AngularFire更新用戶的個人資料圖片。我使用put
方法返回promise
。在我的promise
內部,我使用observable
更改用戶信息中的圖像URL
。最後,我將圖片的DOM
元素的圖片URL
更改爲用戶信息中的圖片URL
。問題是我的promise
在我的observable
完成更新之前試圖獲取用戶的圖像URL
。有沒有辦法將observable
鏈接到promise
以便promise
只有在observable
完成時纔會繼續? 這裏是我的代碼:鏈接可觀察和承諾
authService.ts
updatePicture(profilePicture){
//first put the pictuer in the storage
return storageRef.put(profilePicture)
.then(snapshot => {
downloadURL = snapshot.downloadURL;
})
//this is where I use the observable to update user info
.then(() => {
this.getUserAuth().subscribe(userAuth => {
userAuth.updateProfile({
displayName:userAuth.displayName,
photoURL:downloadURL
})
})
})
}
user.component.ts
// I want this "then" to only happen when my observable is complete.
authService.updatePicture().then(p => {
document.querySelector('img').src = this.userAuth.photoURL);
}