javascript - 在 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;
}
);
}
解决方案
尝试这个:
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 考试
推荐阅读
- ruby-on-rails - Solidus - 无法上传或查看图像(已安装 ImageMagick)
- qt - 如何将 QString 转换为 ascii?
- python - Selenium 网站登录脚本。- 安全地存储凭据
- javascript - Angular Animation 不断在每个动作上重新启动
- rest - 使用 REST api 更新 Sharepoint 元数据会出现 400 错误请求错误
- python - 磁盘上的镶木地板与 cassandra 大小
- spring-boot - Spring Boot 2.3.1、JUnit 5、Maven 3.6.3 - Maven 生命周期“测试”不运行测试套件
- javascript - 流畅的javascript进度条
- c# - 如何制作弹出警报而不是 ArgumentNullException 页面?
- python - 这是我的一个问题,因为我是编程初学者?我想问一个与Python相关的简单问题