我怎样才能用switchmap重写下面的代码

How can i rewrite the following code with switchmap

您好,我有一个使用 rxjs 库的小代码片段,如下所示。它工作正常。但是我想使用 switchmap 重新编写它。我尝试了所有选项,但出现错误。想知道是否有人可以帮助我。

this.campaignControl.valueChanges.subscribe(
(value) => {
    this.flightsService.getUnpaginatedFlightsWithinRange(
          {
                 campaignId : value,
                 jobStatuses: this.flightStatusIds,
                 rangeStartDate: 
                 (this.rangeControl.value[0]).toISOString(),
                 rangeEndDate: (this.rangeControl.value[1]).toISOString()
          }
).subscribe(
      (flightsUnpaginated) => {
             this.flights = flightsUnpaginated;
            }
         );
   }
);

谢谢

我相信您正在寻找这样的东西:

this.campaignControl.valueChanges.pipe(
  switchMap(value => this.flightsService.getUnpaginatedFlightsWithinRange({
    campaignId : value,
    jobStatuses: this.flightStatusIds,
    rangeStartDate: (this.rangeControl.value[0]).toISOString(),
    rangeEndDate: (this.rangeControl.value[1]).toISOString()
  }),
  tap(flightsUnpaginated => this.flights = flightsUnpaginated)
).subscribe();