我成功使用以下方法建立了对应用程序负载的影响:
// in providers section of file: 'app.module'
{
provide: APP_INITIALIZER,
useFactory: (store: Store<AppState>) => {
return async () => {
store.dispatch(fetchUser());
};
},
multi: true,
deps: [Store],
},
我想等待fetchUser()操作完成(并触发它为“成功”或“失败”操作...
我在同一段代码中尝试过类似的操作:
store.pipe(select('user'))
.subscribe((userState) => {
debugger;
store.dispatch(fetchTeam(user.team.id));
});
fetchTeam()
的作用破坏了应用程序的ngrx部分,调试器崩溃。我还尝试过滤流,然后在tap
中调用效果,这不会使商店崩溃,但不会触发效果。
我需要使用商店的user
部分中的数据来获取team
,所以我需要等待user
效果返回一些数据后才能使用fetchTeam
效果...谢谢您的帮助!