Ich versuche, Profilbild des Benutzers mit AngularFire zu aktualisieren. Ich benutze die put
Methode, die eine promise
zurückgibt. Innerhalb meiner promise
benutze ich eine observable
, um das Bild URL
in Benutzerinformationen zu ändern. Am Ende ändere ich das Bild URL
des Bildes DOM
Element auf das Bild URL
in Benutzerinformationen. Das Problem ist, dass mein promise
versucht, das Bild des Benutzers URL
zu erhalten, bevor meine observable
Aktualisierung getan wird. Gibt es eine Möglichkeit, eine observable
zu promise
zu verketten, so dass promise
nur fortgesetzt wird, wenn observable
abgeschlossen ist? Hier ist mein Code:Verkettung beobachtbar und Versprechen
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);
}