I'm pretty new to angular and rxjs and I just can't get it solved. I know my code is wrong, but i don't know how to write it correctly.
I'm fetching a JSON via a HTTP Request, the JSON contains data in an array. After that i want to loop through the array inside the JSON data and fetch additional data of another HTTP Endpoint.
I looked into flatMap, switchMap, and so on and I can't figure to combine these commands in my case.
Thank you guys!
My Code so far:
checkMatches() {
this.http.get<{
message: string,
result: any}>
(BACKEND_URL + 'matches')
.pipe(map((matchData) => {
return {matches: matchData.result.map(match => {
this.userService.getUserData(match.matchedUser).subscribe(userData => {
console.log(userData);
}
);
return {
id: match._id,
matchedUser: match.matchedUser,
firstMatch: match.firstMatch,
name: userData.userName,
img: userData.userImg,
status: match.status,
};
})};
}))
.subscribe(transformedMatchData => {
console.log(transformedMatchData);
});
}