首页 > 解决方案 > 为什么我的 ngrx Effect 将字符串参数转换为数组?

问题描述

行动

我有以下动作:

export const searchTM = createAction(
    IocActionTypes.SearchTM,
    props<{tm: string}>()
);

零件

我的一个组件中有以下代码:

this.store.dispatch(searchTM(value));  

value字符串在哪里03F

效果

在我的 ngrx 效果文件中,我有以下内容:

searchTM$ = createEffect(() => this.actions$.pipe(
    ofType(iocActions.searchTM),
    mergeMap(val => this.iocService.getGridRowByTM(val.tm)
      .pipe(
        map(rowdataraw => iocActions.searchTMFound({rowdataraw})),
        catchError(() => {
            return EMPTY;
        })
      )
      )
    )
  );

但是当我在 mergeMap 变量上设置一个调试点时val,我看到它是这样出现的:

在此处输入图像描述

标签: angularngrxngrx-storengrx-effects

解决方案


问题是我以错误的格式传递参数。

我正在使用:

this.store.dispatch(searchTM(value));  

我应该在哪里使用:

this.store.dispatch(searchTM({tm: value}));

推荐阅读