Angular 嵌套订阅方法的最佳解决方案是什么

Angular 嵌套订阅方法的最佳解决方案是什么,angular,rxjs,Angular,Rxjs,例如,我有两个嵌套的subscribe方法。有时我有两个以上的方法,它们需要连接,所以当第一个方法结束时,第二个方法应该开始,等等。。。 什么是最好的解决方案,这样他们可以等待另一个,但不以这种方式嵌套 this.userService.postUser(userModel).subscribe(postUser => { this.userService.getAllUsers().subscribe(users => { }) }) 如果它们需要按顺序运行

例如,我有两个嵌套的subscribe方法。有时我有两个以上的方法,它们需要连接,所以当第一个方法结束时,第二个方法应该开始,等等。。。 什么是最好的解决方案,这样他们可以等待另一个,但不以这种方式嵌套

this.userService.postUser(userModel).subscribe(postUser => {
     this.userService.getAllUsers().subscribe(users => {
     })
})


如果它们需要按顺序运行,您可以使用
switchMap
操作符:

this.userService
.postaser(用户模型)
.pipe(switchMap((positioner/*未使用?*/)=>this.userService.getAllUsers())
.subscribe(用户=>{})

这不起作用,您需要使用一个展平操作符而不是贴图操作符,例如mergeMap或switchMap。我的错–我确实在寻找switchMap。