我如何以反应形式检索我的url值?我不知道如何从Observable提取值以由存在Observable的函数返回。我只需要从中返回一个值即可,
uploadFile(event) {
const file = event.target.files[0];
const filePath = Date.now().toString();
const fileRef = this.storage.ref('/referentiels/' + filePath);
const task = this.storage.upload('/referentiels/' + filePath, file);
this.uploadPercent = task.percentageChanges();
task.snapshotChanges().pipe(
finalize(() => {
this.downloadURL = fileRef.getDownloadURL();
this.downloadURL.subscribe((url) => {
return url
});
}))
.subscribe()
}
onSaveReferentiel() {
const nomSS = this.referentielForm.get('nomSS').value;
const speSS = this.referentielForm.get('speSS').value;
const webSS = this.referentielForm.get('webSS').value;
const newReferentiel = new Referentiel (nomSS, speSS, webSS, ---url---);
this.referentielsService.createNewReferentiel(newReferentiel);
this.router.navigate(['/referentiels']);
}
答案 0 :(得分:1)
尝试一下
uploadFile(event) {
const file = event.target.files[0];
const filePath = Date.now().toString();
const fileRef = this.storage.ref('/referentiels/' + filePath);
const task = this.storage.upload('/referentiels/' + filePath, file);
this.uploadPercent = task.percentageChanges();
task.snapshotChanges().pipe(
finalize(() => {
this.downloadURL = fileRef.getDownloadURL();
this.downloadURL.subscribe(url => this.url = url
);
}))
.subscribe())
}