我正在使用Angular和Firebase存储上载图像,当我尝试在urlImg
的{{1}}中打印它时,我的undefined
是console.log
的问题tap
。
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);
}
})
);
答案 0 :(得分:0)
一种选择是利用已完成的订阅部分。然后,您可以确保this.urlImg具有值。
.subscribe(
url => this.urlImg = url,
err => console.error('Request for URL failed: ' + err),
() => {
// operations when URL request is completed
}
)