将promise属性更改为Angular可观察的值

时间:2020-06-29 16:33:21

标签: javascript angular promise observable

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

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;
    }
  );
}

enter image description here

3 个答案:

答案 0 :(得分:0)

用地图替换第二个mergeMap运算符应该起作用。

 .pipe(
   mergeMap(data => this.getFiles(data.ref)),
   map((data) => data.map(item => [item, item.getDownloadURL(), item.getMetadata()])
 ),

答案 1 :(得分:0)

尝试一下:

NSIndexPath *thePath = [NSIndexPath indexPathForRow:self.yourArray-1 inSection:0];
[self.tableView scrollToRowAtIndexPath:thePath atScrollPosition:(UITableViewScrollPositionBottom) animated:NO];

您可以检查此示例吗?这是您的问题吗? Stackblitz exam

答案 2 :(得分:0)

我能够通过以下解决方案解决问题

ngOnInit() {
    this.route.params
    .pipe(
        mergeMap(data => this.getFiles(data.ref)),
        map((data) => {
        const newArrayReferences = [];

        data.forEach(async (item, index) => {
            newArrayReferences.push({
            item,
            downloadUrl: await item.getDownloadURL().then((promisseReturn) => promisseReturn ),
            metaData: await item.getMetadata().then((promisseReturn) => promisseReturn )
            });
        });

        return newArrayReferences;
        }),
    )
    .subscribe(
        (data) => {
        console.log(data);
        this.listReferences = data;
        }
    );
}
相关问题