Rxjs Ionic2/角度:如何知道两个不同的观测值何时终止?

Rxjs Ionic2/角度:如何知道两个不同的观测值何时终止?,rxjs,reactive-extensions-js,Rxjs,Reactive Extensions Js,这里有一个初学者问题:在Ionic2组件中,我有两个不同的服务调用,使用可观察对象: getTimelineEvents() { this.receiptsEventsRequestState = RequestState.Pending; this.chargesEventsRequestState = RequestState.Pending; this.miscService.getCustomerReceiptsEvents() .subscri

这里有一个初学者问题:在Ionic2组件中,我有两个不同的服务调用,使用可观察对象:

  getTimelineEvents() {
    this.receiptsEventsRequestState = RequestState.Pending;
    this.chargesEventsRequestState = RequestState.Pending;

    this.miscService.getCustomerReceiptsEvents()
      .subscribe(
        (events: TimelineEvent[]) => {
         this.receiptsEventsRequestState = RequestState.Success;
         this.receiptsEvents = events;
         },
      );

    this.miscService.getCustomerChargesEvents()
      .subscribe(
        (events: TimelineEvent[]) => {
        this.chargesEventsRequestState = RequestState.Success;}
        this.chargesEvents = events;
      );

  }
我想知道
getCustomerReceiptsEvents
getCustomerChargesEvents
何时成功,以便调用另一个方法(此方法需要chargesEvents和receiptsEvents数据)


谢谢。

您可以等待两个观测值完成,然后使用。它们仍将并行执行

Observable.forkJoin(
  this.miscService.getCustomerReceiptsEvents(),
  this.miscService.getCustomerChargesEvents(),
)
  .subscribe(([receipts, charges] => {
    console.log('Results', receipts, charges)
  })

在第一次服务调用成功后进行第二次服务调用如何?因为我希望两个请求都能并行执行以保持速度。哇,谢谢,这很有趣!一个问题:目前,如果两个请求中的一个都失败,那么整个过程都会失败。如果两个请求中至少有一个成功,我想调用我的方法怎么办?对不起,不知道。可能是问新问题的最佳选择。