对每个角度为2的数据应用请求操作

时间:2018-09-16 18:20:16

标签: angular

在角度2中,我想调度多个数据的请求。 例如,我有一些用户数据(2个ID),并且想为每个ID申请一个请求。 我的代码:

handleOnBulkAction(actionId) {
  const dataUser = this.userState.bulkList.map((userId) => {
    return {
      item: userId,
    };
  });
  this.dialogRef.afterClosed().subscribe(result => {
      if (result) {
        dataUser.forEach(user => {
          console.log(user); //it return the id
          this.store.dispatch(new user.DeleteAction({
              user: user.item,
              organisationId: this.organisationId
          }));
        });
      }
      this.dialogRef = null;
  });
  return;
}

它给出了错误:

ERROR TypeError: user.DeleteAction is not a constructor

你有什么主意吗?

编辑: 动作/user.ts

export class DeleteAction implements Action {
  type = ActionTypes.DELETE;

  constructor(public payload: any) {
  }
}

效果:

@Effect()
delete$: Observable<Action> = this.actions$
.ofType(user.ActionTypes.DELETE)
.map(toPayload)
.switchMap((args) => {
  return this.userService.deleteUser(args.user)
    .concatMap(response => [
      new user.DeleteSuccessAction(args.user),
      new organisation.FetchOneAction(args.organisationId)
    ])
    .catch((error) => [
      new layout.HideLoadingAction(),
      new user.ChangeStatusErrorAction(error)
    ]);
});

服务:

 public deleteUser(user) {
  return this.http.delete(`${this.userApi}/${user.id}`, {
    withCredentials: true,
  }).map(() => {
   }).catch(this.errorService.handleError);
 }

0 个答案:

没有答案