首页 > 解决方案 > 在 Angular observable 中将 promise 属性更改为她的值

问题描述

我需要将值添加到数组的映射中。该价值来自承诺,我无法添加价值本身。

ngOnInit() {
  this.route.params
  .pipe(
    mergeMap(data => this.getFiles(data.ref)),
    mergeMap((data, index) => {
      return data.map(item => Array(item, item.getDownloadURL(), item.getMetadata()))
    }),
  )
  .subscribe(
    (data) => {
      console.log(data);
      this.listReferences = data;
    }
  );
}

在此处输入图像描述

标签: javascriptangularpromiseobservable

解决方案


尝试这个:

  this.route.params
.pipe(
  mergeMap(data => of(this.getFiles(data.ref))
    .pipe(
      map((item) => ({
        item,
        downloadUrl: item.getDownloadURL(),
        metaData: item.getMetadata()
      }))
    )
  ),
  toArray(),
)
.subscribe(
  (data) => {
    console.log(data);
    this.listReferences = data;
  }
);

你能检查一下这个例子吗?这是否与您的问题相似。 Stackblitz 考试


推荐阅读