Updated on Kisan Patel
How to combine the results of two observable in angular?
Use forkJoin
to join multiple results.
// Get all posts // Get the user of each post // Get the todos for each user postData$ = this.http.get<Post[]>(this.postUrl).pipe( switchMap(posts => forkJoin( posts.map(post => forkJoin([ this.http.get<User>(`${this.userUrl}/${post.userId}`), this.http.get<ToDo[]>(`${this.todoUrl}?userId=${post.userId}`) ]).pipe( map(([user, todos]) => ({ post: post, userName: user.name, todos: todos })) ) ) ) ) );