【问题标题】:How i can retrieve value observable in reactiveform?我如何以反应形式检索可观察值?
【发布时间】:2018-12-26 15:31:02
【问题描述】:

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

【问题讨论】:

  • 你想达到什么目标?
  • 目前你遇到了什么错误?
  • 您是否正在尝试控制订阅数据的任何值?
  • 我重新提出了我的问题

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


【解决方案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())

}

【讨论】:

  • 先试试console.log(url)里面的subscribe方法
  • 不客气,兄弟。很高兴能为您提供帮助!
猜你喜欢
  • 2019-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-13
  • 2019-09-24
  • 2019-03-31
  • 2018-11-28
相关资源
最近更新 更多