Home > Net >  Angular & ngrx: Unexpected token. A constructor, method, accessor, or property was expected
Angular & ngrx: Unexpected token. A constructor, method, accessor, or property was expected

Time:10-12

I have a table where I add and delete and update data for that I use ngrx doing the CRUD method, I have a problem when I try to recover the error if there is one in my effect components. The error is in my effect file

Here is the error: Unexpected token. A constructor, method, accessor, or property was expected

actions

export const ActionTypes = {

   // addSucces: '[PeriodicElement] addSucces',
  addError: '[PeriodicElement] addError',

  preAdd: '[PeriodicElement] preAdd',
  Add: '[PeriodicElement] Add',

};

export const addTable = createAction(
  ActionTypes.Add,
  props<{ payload: PeriodicElement }>()
);

export const addTableError = createAction(
  ActionTypes.addError,
  props<{ payload: any }>()
);

effect

  addTable = createEffect(() =>
    this.actions.pipe(
      ofType(TableActions.ActionTypes.preAdd),
      mergeMap((name: any) =>
        this.tableService.create(name.payload).pipe(
          map(
            (table) => TableActions.addTable({ payload: table }),
            catchError((error) => of(TableActions.addTableError({payload: error})))
            )
          )
        )
      )
    )
  );

I don't know if this is the way to recover the error

CodePudding user response:

catchError shouldn't be inside of the map operator but on the same level within the pipe operator.

addTable = createEffect(() =>
    this.actions.pipe(
      ofType(TableActions.ActionTypes.preAdd),
      mergeMap((name: any) =>
        this.tableService.create(name.payload).pipe(
          map((table) => TableActions.addTable({ payload: table })),
          catchError((error) => of(TableActions.addTableError({payload: error})))
        )
      )
    )
  );
  • Related