繁体   English   中英

Rxjs - combinelatest 后如何调用两个 httpService?

[英]Rxjs - How to call two httpService after combinelatest?

我不知道这是否是更好的解决方案,但我需要一个订阅两个 ngrx 选择器并将其用作两个 http 服务的参数的 function,我使用了 combineLatest:

  combineLatest([this.selectedCompany$, this.account$]).subscribe(res => {
  this.idCompany = res[0]!.id;
  this.account = res[1];
  this.getDashboardCardService(this.account!.id.toString(), this.idCompany.toString(), 'time');
  this.getavailableSpaceService(this.idCompany).subscribe(res => {
      this.space = res;
  })

}).unsubscribe();

我使用 combineLatest 订阅两个 ngrx 选择器,在订阅中我需要使用这些值来执行两个 http 调用,getDashboardCard 和可用。 它有效,但我不喜欢它......这是更好的解决方案吗?

简而言之,您应该在.pipe(combineLatest switchMap pipe调用另一个服务。

也许你可以用它来让你朝着正确的方向前进?

这里我使用了更高阶的可观察运算符( concatMap );

combineLatest([this.selectedCompany$, this.account$]).pipe(
  concatMap(([company, account]) => forkJoin([
    this.getDashboardCardService(
      account!.id.toString(), 
      company!.id.toString(), 
      'time'
    ),
    this.getavailableSpaceService(company!.id)
  ]))
).subscribe(([res1, res2]) => {
  this.space = res2;
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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