(角度和ngrx)在应用加载时会运行几种效果,而效果的顺序很重要

时间:2020-09-09 22:30:22

标签: ngrx ngrx-store ngrx-effects

我成功使用以下方法建立了对应用程序负载的影响:

// 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效果...谢谢您的帮助!

0 个答案:

没有答案