Node.js 角度Ngrx中的火效应法时的误差获取

Node.js 角度Ngrx中的火效应法时的误差获取,node.js,angular,ngrx,ngrx-effects,Node.js,Angular,Ngrx,Ngrx Effects,我使用Angular 7 NGRX状态系统 当我从我的组件中分派这个方法时,我得到了一个错误 参数是正确的。我都检查过了。我想我犯了一个错误,使用了“mergeMap”和“return”错误的值 我错在哪里了 错误: ERROR Error: Effect "StudentEffects.addReview$" dispatched an invalid action: [object Object] ..... ERROR TypeError: Actions must have a typ

我使用Angular 7 NGRX状态系统

当我从我的组件中分派这个方法时,我得到了一个错误

参数是正确的。我都检查过了。我想我犯了一个错误,使用了“mergeMap”和“return”错误的值

我错在哪里了

错误:

ERROR Error: Effect "StudentEffects.addReview$" dispatched an invalid action: [object Object] .....

ERROR TypeError: Actions must have a type property
export class AddReview implements Action {
  readonly type = ActionTypes.AddReview;
  constructor(public payload: { guruId: string, review: IReview }) { }
}


export class AddReviewSuccess implements Action {
  readonly type = ActionTypes.AddReviewSuccess;
  constructor(public payload: { guruId: string, review: IReview }) { }
}
  @Effect()
  addReview$ = this.actions$.pipe(
    ofType<StudentActions.AddReview>(StudentActions.ActionTypes.AddReview),
    mergeMap(action => {

      return this.personApi.findOne({ where: { id: action.payload.guruId } }).pipe(
        map((guru: Person) => {

          let reviews: Array<IReview> = Array.isArray(guru._reviews) ? guru._reviews : [];
          reviews.push(action.payload.review);

          let attrs = {
            _reviews: reviews,
          };

          return this.personApi // => Not goes inside. I get error.
            .patchAttributes(guru.id, attrs)
            .pipe(
              map(person => {

                this.notificationService.createNotification(
                  'success', 'Success', 'Your review successfully saved.'
                );

                this.logService.groupLog('AddReview', action, person);

                return new StudentActions.AddReviewSuccess({ guruId: guru.id, review: action.payload.review });

              }),
              catchError(() => {
                // this.notificationService.createNotification(
                //   'error',
                //   'Error',
                //   'There is an error on save'
                // );
                console.error('There was an error');
                return EMPTY;
              })
            );
        }),
        catchError(() => EMPTY)
      );
    })
  );
case ActionTypes.AddReview: {
      return {
        ...state,
        loading: true
      };
}
case ActionTypes.AddReviewSuccess: {
  return {
    ...state,
    reviews: [
      ...state.reviews,
      { guruId: action.payload.guruId, review: action.payload.review }
    ],
    loading: false
  };
}

行动方法:

ERROR Error: Effect "StudentEffects.addReview$" dispatched an invalid action: [object Object] .....

ERROR TypeError: Actions must have a type property
export class AddReview implements Action {
  readonly type = ActionTypes.AddReview;
  constructor(public payload: { guruId: string, review: IReview }) { }
}


export class AddReviewSuccess implements Action {
  readonly type = ActionTypes.AddReviewSuccess;
  constructor(public payload: { guruId: string, review: IReview }) { }
}
  @Effect()
  addReview$ = this.actions$.pipe(
    ofType<StudentActions.AddReview>(StudentActions.ActionTypes.AddReview),
    mergeMap(action => {

      return this.personApi.findOne({ where: { id: action.payload.guruId } }).pipe(
        map((guru: Person) => {

          let reviews: Array<IReview> = Array.isArray(guru._reviews) ? guru._reviews : [];
          reviews.push(action.payload.review);

          let attrs = {
            _reviews: reviews,
          };

          return this.personApi // => Not goes inside. I get error.
            .patchAttributes(guru.id, attrs)
            .pipe(
              map(person => {

                this.notificationService.createNotification(
                  'success', 'Success', 'Your review successfully saved.'
                );

                this.logService.groupLog('AddReview', action, person);

                return new StudentActions.AddReviewSuccess({ guruId: guru.id, review: action.payload.review });

              }),
              catchError(() => {
                // this.notificationService.createNotification(
                //   'error',
                //   'Error',
                //   'There is an error on save'
                // );
                console.error('There was an error');
                return EMPTY;
              })
            );
        }),
        catchError(() => EMPTY)
      );
    })
  );
case ActionTypes.AddReview: {
      return {
        ...state,
        loading: true
      };
}
case ActionTypes.AddReviewSuccess: {
  return {
    ...state,
    reviews: [
      ...state.reviews,
      { guruId: action.payload.guruId, review: action.payload.review }
    ],
    loading: false
  };
}
效果方法:

ERROR Error: Effect "StudentEffects.addReview$" dispatched an invalid action: [object Object] .....

ERROR TypeError: Actions must have a type property
export class AddReview implements Action {
  readonly type = ActionTypes.AddReview;
  constructor(public payload: { guruId: string, review: IReview }) { }
}


export class AddReviewSuccess implements Action {
  readonly type = ActionTypes.AddReviewSuccess;
  constructor(public payload: { guruId: string, review: IReview }) { }
}
  @Effect()
  addReview$ = this.actions$.pipe(
    ofType<StudentActions.AddReview>(StudentActions.ActionTypes.AddReview),
    mergeMap(action => {

      return this.personApi.findOne({ where: { id: action.payload.guruId } }).pipe(
        map((guru: Person) => {

          let reviews: Array<IReview> = Array.isArray(guru._reviews) ? guru._reviews : [];
          reviews.push(action.payload.review);

          let attrs = {
            _reviews: reviews,
          };

          return this.personApi // => Not goes inside. I get error.
            .patchAttributes(guru.id, attrs)
            .pipe(
              map(person => {

                this.notificationService.createNotification(
                  'success', 'Success', 'Your review successfully saved.'
                );

                this.logService.groupLog('AddReview', action, person);

                return new StudentActions.AddReviewSuccess({ guruId: guru.id, review: action.payload.review });

              }),
              catchError(() => {
                // this.notificationService.createNotification(
                //   'error',
                //   'Error',
                //   'There is an error on save'
                // );
                console.error('There was an error');
                return EMPTY;
              })
            );
        }),
        catchError(() => EMPTY)
      );
    })
  );
case ActionTypes.AddReview: {
      return {
        ...state,
        loading: true
      };
}
case ActionTypes.AddReviewSuccess: {
  return {
    ...state,
    reviews: [
      ...state.reviews,
      { guruId: action.payload.guruId, review: action.payload.review }
    ],
    loading: false
  };
}

我找到了bug。

有效方法:

这行:
map((古鲁:人)=>{


应该是:
mergeMap((guru:Person)=>{

没有足够的细节来了解发生了什么,请向您的帖子提供您的操作。@penleychan我编辑了我的问题。
EMPTY
?@Yevgeniy.Chernobrivets关于
return
map
有一个问题。EMPTY甚至不起作用。至少目前我看不出map return有任何问题,我想可能是这样的ur api返回并出错,然后进入catchError,而
EMTY
实际上并不是一个动作。