“ AuthEffects.googleSignIn”调度了无效的操作,并且操作必须具有type属性

时间:2019-08-20 20:36:15

标签: javascript angular typescript rxjs ngrx

我一直收到以下错误:

  • 效果“ AuthEffects.googleSignIn”调度了无效操作:[对象对象]
  • 未捕获的TypeError:操作必须具有type属性

如下所示:

enter image description here enter image description here

我该如何解决?登录会按预期进行,但我不确定如何解决该问题:

auth.effects.ts

b.execute_script('document.getElementById("contenteditable-root").innerHTML = "hi";')

auth.actions.ts

  @Effect()
  googleSignIn = this.actions.pipe(
    ofType(authActions.googleSignIn),
    mergeMap(() =>
      from(this.authService.googleSignIn()).pipe(
        map(() => this.getAuthData,
          catchError(err =>
            of({ error: err.message })
          )
        )
      )
    )
  );

  @Effect()
  getAuthData = this.actions.pipe(
    ofType(authActions.getAuthData),
    mergeMap(() => (
        this.afAuth.authState.pipe(
          map((authData: AuthState) => {
            if (authData) {
              const parsedAuthData: Partial<AuthState> = this.authService.parseAuthData(authData);
              return authActions.authDataRetrieved({ payload: parsedAuthData });
            } else {
              return authActions.authDataNotRetrieved();
            }
          }),
          catchError(error => {
            this.logger.debug(error);
            return of(authActions.authError({ errorMessage: error.message, errorCode: error.code }));
          })
        )
      )
    )
  );

1 个答案:

答案 0 :(得分:1)

您应该从googleSignIn效果中返回一个操作,诸如此类

 getPosts$ = createEffect(() =>
    this.actions$.pipe(
      ofType(PostActions.LoadPosts),
      switchMap(_ => {
        return this.postService
          .getPosts()
          .pipe(
            map(
              (posts: IPost[]) => PostActions.LoadPostsSuccess({ posts }), // return an action here
              catchError(errors => of(PostActions.LoadPostsFail(errors)))
            )
          );
      })
    )
  );

我指出您的错误在哪里,以便您可以解决

@Effect()
  googleSignIn = this.actions.pipe(
    ofType(authActions.googleSignIn),
    mergeMap(() =>
      from(this.authService.googleSignIn()).pipe(
        map(() => this.getAuthData, // you need to return an action here
          catchError(err =>
            of({ error: err.message })
          )
        )
      )
    )
  );