angular - 我需要进行两次订阅等待
问题描述
我正在通过项目的 id 获取列表,但现在要获取卡片,我需要获取列表的 id,但是为此,如果您可以指导我了解代码的方式,我需要等待
this.route.paramMap.pipe(
map((param: ParamMap) => {
// @ts-ignore
return param.params.id;
})
).subscribe(prodId => {
this.id = prodId;
console.log("Titulo de Proyecto", prodId)
this.API.getNombreProyecto(this.id).subscribe(prod => {
this.project = prod;
});
});
this.API.getListas(this.id)
.subscribe((data: Customer[]) => {
console.log('Obtener Listas:::', data);
this.customersx = data;
console.log('Obtener Listas:::',this.customersx);
});
this.API.getCards(this.id)
.subscribe((data: CustomerCards[]) => {
this.defaults.id = this.id;
console.log('Obtener Listas:::', data);
this.customersy = data;
console.log('Obtener Listas:::',this.customersy);
});
解决方案
我完全没有得到您真正想要实现的目标,因为您发布的描述似乎不容易理解。
但我会试着给你一个想法,你怎么能做到这一点。检查下面的代码。
this.route.paramMap
.pipe(
switchMap((param: ParamMap) => {
this.id = param.params.id;
return forkJoin([
this.API.getNombreProyecto(this.id),
this.API.getListas(this.id),
this.API.getCards(this.id)
]);
})
)
.subscribe(([project, customersx, data])=>{
this.project = project;
this.customersx = customersx;
this.customersy = data;
})
现在通过引用上面的代码,您可以尝试修改您的代码以使其按您想要的顺序。
推荐阅读
- ios - 从 TestFlight 运行时,应用程序中的速率不工作/显示
- html - 为什么这不在中心?
- angular - 在 Angular 7 中使用 ngx-soap 使用 SOAP Web 服务
- rust - 无法验证生成的可执行文件是带有“cargo readobj”的 ARM 二进制文件:没有这样的子命令
- python - 具有多索引的系列点积
- css - CSS 显示/隐藏 Div 兄弟元素
- java - 使用 Spring Boot 对数据库的错误查询
- google-cloud-functions - 谷歌云函数 - 用回调调用另一个
- c# - 从其他列表添加列表
- python - 用于变量声明的 Python 版本的 ifelse