使用concatMap对多个可观察对象进行排序

问题描述 投票:0回答:2

我正在尝试使用RxJS concatMap对2个可观察对象进行排序,以便在调用服务以返回对象以将其绑定到Angular 9中的Mat-Table之前,它返回employeeID。但是我不确定如何编写语法正确。第一个可观察到的实际上是我创建的行为主题,旨在让组件订阅应用程序中的任何位置。第二个是来自Web api的http响应。

我一直在看这里的示例,并试图弄清楚它,但只是在敲打键盘。RxJS concatMap

//first observable (actually a Behavior Subject)
this.userService.currentEmployeeId.subscribe(empId => this.employeeID = empId)

//second observable
this.service.getMissingContractsSummary(this.employeeID)
.subscribe(
  response => {        
    this.dataSource = new MatTableDataSource<Contractsummary>(response);
    this.dataSource.paginator = this.paginator;
  }
);
angular rxjs angular2-observables
2个回答
0
投票

请尝试以下方式:


0
投票

concatMap应该可以,但是根据您想要的行为,您可能需要尝试switchMap。无论哪种情况,语法都是相似的。您将需要将该操作传递给可观察到的currentEmployeeId。当它发出新值时,switchMap函数可以将该值传递给服务的get函数以返回该可观察值。然后,您可以像在示例代码中一样进行订阅。

© www.soinside.com 2019 - 2024. All rights reserved.