angular - 从 typeOf ngrx 效果中获取参数
问题描述
我有这样的东西
ngOnInit() {
this.store.dispatch(new TutorialActions.GetTutorials(1, 20));
}
export class GetTutorials implements Action {
readonly type = GET_TUTORIALS
constructor(public number: number, public offset: number) {}
}
然后我有这样的效果
export class TutorialEffects {
loadTutorials$ = createEffect(() =>
this.action$.pipe(
ofType(TutorialActions.GET_TUTORIALS),
switchMap(() =>
this.tutorialService.getAll(0, 20).pipe(
map((tutorial: Tutorial[]) => new TutorialActions.SuccesGetTutorials(tutorial)),
catchError((error) => of (error))
)
)
)
);
}
问题出在ofType(TutorialActions.GET_TUTORIALS)
, this.tutorialService.getAll(0,20)
。
该值应该从ngOnInit
函数传递并且可以是动态的?
解决方案
是的,您可以访问操作对象。所以你可以访问它的属性。
export class TutorialEffects {
loadTutorials$ = createEffect(() =>
this.action$.pipe(
ofType(TutorialActions.GET_TUTORIALS),
switchMap((action: any) =>
this.tutorialService.getAll(action.number, action.offset).pipe(
map((tutorial: Tutorial[]) => new TutorialActions.SuccesGetTutorials(tutorial)),
catchError((error) => of (error))
)
)
)
);
}
推荐阅读
- python - 网页抓取协助
- pandas - 如何在 ND4j 中读取 numpy 数组
- c++ - 需要帮助在 C++ 中使用嵌套的 for 循环
- homebrew - 拒绝链接 macOS 提供的软件:libiconv
- r - 为什么 rbind 不能追加这两个数据集?
- python - 绘制 scikit-learn 数据集训练和测试数据时出错
- c# - 如何在 EF Core 3 中拦截数据库操作?
- php - 如何确保 WordPress 插件的 POST 请求是由管理员发出的?
- python - 从 numpy 数组中删除换行符
- android - 在 Android Studio 中将 EditText 转换为 int