[英]Waiting for observable to finish - Angular
我正在使用Angular和Firebase存儲上載圖像,當我嘗試在tap
內的console.log
打印urlImg
時,我urlImg
了一個undefined
的問題。
this.snapshot = this.snapshot = this.task.snapshotChanges().pipe(
finalize(() => {
this.storage
.ref(path)
.getDownloadURL()
.subscribe(url => {
this.urlImg = url; // with this you can use it in the html
});
}),
tap(snap => {
if (snap.bytesTransferred === snap.totalBytes) {
// Update firestore on completion
//Code to upload on completion
console.log("url");
console.log(this.urlImg);
}
})
);
一種選擇是利用已完成的訂閱部分。 然后,您可以確保this.urlImg具有值。
.subscribe(
url => this.urlImg = url,
err => console.error('Request for URL failed: ' + err),
() => {
// operations when URL request is completed
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.