简体   繁体   中英

Angular async pipe with rxjs switchmap

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?

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}))
  )),
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM