【问题标题】:NGRX Effects and Angular FireNGRX 效果和角火
【发布时间】:2021-08-30 01:55:24
【问题描述】:

想知道是否有人可以帮助我了解这里发生了什么。

我正在运行一个调用 auth 服务的 ngrx 效果,对服务的调用正常工作,如果失败,它也会正确地进入 catch 错误。

问题是,如果它成功了,我想将原始操作传递给下一个操作员(而不是调用 auth 服务的响应)。

但是当我这样做时,我总是得到一个未定义的。

  login$ = createEffect(
    () =>
      this.actions$.pipe(
        ofType(AuthActions.login),
        switchMap(action => {
          return this.auth.login(action.user.email, action.password);
        }),
        map(action => {  **// This is undefined, but what i want is the action object** 
          console.log(action);
          this.store.dispatch(
            loginSuccessful({
              user: action,
            })
          );
        }),
        catchError((err) => {
          console.log('Received error from AngularFire:', err);
          return of(err);
        })
      ),
    { dispatch: false }
  );

【问题讨论】:

    标签: angular rxjs firebase-authentication ngrx ngrx-effects


    【解决方案1】:

    刚刚发现我可以用点击替换switchMap和地图。

    login$ = createEffect(
        () =>
          this.actions$.pipe(
            ofType(AuthActions.login),
            tap(action => {
              return this.auth.login(action.user.email, action.password);
            }),
            tap(action => {   
              console.log(action);
              this.store.dispatch(
                loginSuccessful({
                  user: action,
                })
              );
            }),
            catchError((err) => {
              console.log('Received error from AngularFire:', err);
              return of(err);
            })
          ),
        { dispatch: false }
      );
    

    【讨论】:

      猜你喜欢
      • 2019-07-02
      • 2018-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-02
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多