我是angular和rxjs的新手,我需要知道如何读取地图上来自forkJoin的数据。
ngOnInit(): void {
this.serviceData.currentService.subscribe(service =>
this.serviceFam.getAllFamilles().pipe(
switchMap(familles =>
forkJoin(
familles.map(f => forkJoin(
this.serviceAffecter.getAffecterServiceFamille(service, f.nom),
this.serviceOpe.getOperationsServiceFamille(service, f.nom)
).pipe(
map(([listAffecter, listeOperations]) => [f, listAffecter, listeOperations])
)
)
)
)
).pipe(switchMap((data: [Famille, Affecter, Operation][]) => {
return forkJoin(data.map((f, a, o) => {
//Here I want to read my data
}));
}))
);
this.serviceData.changeAffaire(4);
}
答案 0 :(得分:0)
阅读起来很混乱,但是在switchMap
的代码内,但是您可以使用https://github.com/Faltenreich/SkeletonLayout运算符记录响应。
forkJoin(
familles.map(f => forkJoin(
this.serviceAffecter.getAffecterServiceFamille(service, f.nom),
this.serviceOpe.getOperationsServiceFamille(service, f.nom)
).pipe(
tap(res => {
console.log(res);
}),
map(([listAffecter, listeOperations]) => [f, listAffecter, listeOperations])
))
)