How can I retrieve all users based on their user id, iterate through them, and display all posts and comments when a specific user is clicked?
You can fetch the posts from the following API: https://jsonplaceholder.typicode.com/posts
And you can get their comments from this API: https://jsonplaceholder.typicode.com/comments
Here is my example project on stackblitz: https://stackblitz.com/edit/angular-g5fqzi
getUserPosts(userId: number) {
this.http.get(`${this._postsURL}`)
//.pipe(filter(data => userId === userId))
//this.http.get(`${this._postsURL}/${userId}`)
.subscribe(data => {
//this.UserPosts = data;
let resources = data[userId];
this.UserPosts = resources;
console.log(this.UserPosts);
})