链接一系列HttpClient调用的“最佳实践”是什么(假设当前调用取决于先前调用的结果)?以下解决方案是有效的,但显然不建议这样做。每个get返回一个Observable。在解决方案(RxJs中的较新方法)中首选使用“管道”运算符。
ngOnInit() {
this.firstService.get().subscribe((first) => {
this.secondService.get().subscribe(second => {
this.thirdService.get().subscribe(third => {
... possibly more nested calls ...
})
})
})
}
Run Code Online (Sandbox Code Playgroud)