Angular 角度中的管道和贴图

Angular 角度中的管道和贴图,angular,dictionary,pipe,Angular,Dictionary,Pipe,我试图在一个.Pipe()语句中使用多个map(),但它不起作用。它不会给我错误,但也不会给我想要的输出。下面是示例代码 makePurchase$ = createEffect(() => this.actions$.pipe( ofType(makePurchase), mergeMap(({ elementId }) => this.simStateService.makePurchase(elementId) .pipe(

我试图在一个.Pipe()语句中使用多个map(),但它不起作用。它不会给我错误,但也不会给我想要的输出。下面是示例代码

makePurchase$ = createEffect(() => this.actions$.pipe(
    ofType(makePurchase),
    mergeMap(({ elementId }) =>
      this.simStateService.makePurchase(elementId)
        .pipe(
          map(() => calculateBalance()),
          map(() => makePurchaseSuccess({elementId})),
          catchError((err) => {
            console.log('THERE WAS AN ERROR');
            console.error('error from the thing', err);
            return makePurchase;
          })
        )
    )
  ));

我希望能够通过这两个地图,但只有一个或其他作品。我希望能够在购买成功后调用akePurchaseSuccess({elementId})),然后计算余额

不久前我也遇到了同样的问题,事实上我认为你应该检查你是否总是在地图调用之间传输可观察的对象

这是一个rxjs映射函数,而不是内置的javascript函数:您需要将其应用于可观察对象


我希望这对您有所帮助。

您可能想发布您正在调用的函数。.同意,我们需要您在
map()
调用中调用的函数。从概念上讲,在一个
pipe()
中有多个贴图是绝对合适的。不过,我想知道的是,您的两个
map()
函数都没有为其回调接受参数。你确定你不想要
tap()
而不是
map()
?你的目标可能是
tap
操作员。