1
this.users$ = this.http.getUsers(criteria).pipe(
  switchMap(user => this.http.getUserData(user.id)),
  map(res => res.data)
);

I want to assign res.data to user.data But the result is only res.data and its forgetting about user obejct Any suggestions?

1
  • Compose the map onto the inner observable: switchMap(user => this.http.getUserData(user.id).pipe(map(res => { user.data = res.data; return user; }))) Commented Dec 23, 2019 at 0:54

1 Answer 1

3

This should do the trick for you.

this.users$ = this.http.getUsers(criteria).pipe(
  switchMap(user => this.http.getUserData(user.id).pipe(
          map((res) => ({...user, data: res.data}))
  )),
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.