angular - 如果动作是从另一个模块分派的,ngrx 效果不会运行
问题描述
所以这就是我想要做的。
在延迟加载BookmarksModule
功能模块下,我有一个效果,即监听authActions.loginSuccess
w/c 在 w/c 中注册AuthModule
不是延迟加载的。
@Injectable({
providedIn: 'root',
})
export class FavoriteEffects {
getFavoriteAfterLogin$ = createEffect(
() => {
return this.actions$.pipe(
ofType(authActions.loginSuccess),
map(() => favoriteActions.getFavorites())
);
}
);
这authActions.loginSuccess
是发送的方式。
loginCallback$ = createEffect(() => {
return this.actions$.pipe(
ofType(authActions.loginCallback),
exhaustMap(() =>
this.authService.currentUser$.pipe(
map(currentUser => authActions.loginSuccess({ currentUser })),
catchError(error =>
of(authActions.loginFailure({ error: error?.error?.message }))
)
)
)
);
});
loginSuccessRedirect$ = createEffect(
() => {
return this.actions$.pipe(
ofType(authActions.loginSuccess),
tap(() => this.router.navigate([this.redirects.login.success]))
);
},
{ dispatch: false }
);
正如你所看到的,当authActions.loginSuccess
被调度时,它loginSuccessRedirect$
在同一个类中被正确拦截,但是这个动作没有在延迟加载的模块中被拦截?
似乎update-reducers
功能模块的动作是在动作已经被调度之后调度的。loginSuccess
我该如何解决这个问题?
解决方案
推荐阅读
- python - 使用 pip install --target 固定 git 修订的版本号
- javascript - 如何在executeSql中修复“INSERT INTO错误代码:0”
- r - R:在填充了各种长度的 NA 值的数据框中,将每行的第 2 列添加到非 NA 行的最后一列
- javascript - 请解释这个js代码片段发生了什么
- javascript - 为什么 window.open() 和 window.close() 在 Extension 中不起作用?
- microsoft-graph-api - 图形 API - 驱动器上传后更新 SharePoint 库字段
- html - 侧边栏 z-index 始终高于下拉菜单
- python - 我需要以日期格式在第一个多索引上打印一个字符串
- tensorflow - 使用与系统不同的 GCC 从源代码构建 TensorFlow 时包含错误
- jquery - CSS 显示:弹性;在 IE 浏览器中无法正常工作