小编Ric*_*hea的帖子

RxJ中依赖于链的可观察变量

链接一系列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)

rxjs angular angular-httpclient

1
推荐指数
1
解决办法
470
查看次数

标签 统计

angular ×1

angular-httpclient ×1

rxjs ×1