我如何获取可在Reactform中观察到的值?

时间:2018-07-18 16:12:29

标签: angular angularfire2 angular-reactive-forms reactive-forms

我如何以反应形式检索我的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']); 
  }

1 个答案:

答案 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())

}