【问题标题】:getting an error when dispatching store action调度商店操作时出错
【发布时间】:2020-06-12 17:09:03
【问题描述】:

我有一个看起来像这样的模型。

    export class BankAccount {
  id?: string;
  accountNumber: string;
  accountTitle: string;
  userImage: string;
  currentBalance: number;
  email: string;
  phoneNumber: string;
  accountStatus: AccountStatus;
}
export enum AccountStatus {
  Active = 0,
  InActive = 1,
}

并且动作是这样定义的。

export const bankAccountCreating = createAction(
'[Create New Account Component] Account Creating',
 props<{ acct: BankAccount }>()
);

所以我有一个填充、对象和调度的角度形式

 this.store.dispatch(bankAccountCreating({ acct: this.bankAccount }));

这里我得到错误

在 acct 检测到不可序列化的操作

请注意,我没有此操作的减速器,因为它只是触发效果但不会更新商店。

更新

    export class BankAccount {
  id?: string;
  accountNumber: string;
  accountTitle: string;
  userImage?: string;
  currentBalance: number;
  email: string;
  phoneNumber: string;
  // accountStatus: AccountStatus;
}
export enum AccountStatus {
  Active = 0,
  InActive = 1,
}

【问题讨论】:

  • 银行账户是接口吗?
  • 就是上面代码中提到的一个类
  • 尝试将类更改为接口?
  • 实际上有一个带有 2 路绑定的表单,因为我必须在构造函数中对其进行初始化。否则在加载空表单时会出错。
  • 请在下面找到我的回复。

标签: angular ngrx


【解决方案1】:

问题在于您的数据。

你的班级被定义为:-

 export class BankAccount {
  id?: string;
  accountNumber: string;
  accountTitle: string;
  userImage: string;
  currentBalance: number;
  email: string;
  phoneNumber: string;
  accountStatus: AccountStatus;
}

您将当前余额作为字符串发送,该字符串应该是一个数字,accountStatus 作为字符串发送,它需要一个 accountstatus 对象,并且没有用户图像字符串是强制性的。

【讨论】:

【解决方案2】:

类不可序列化,您可以使用接口来解决此问题或禁用可序列化运行时检查。

请参阅docs 了解更多信息。

【讨论】:

  • 实际上有一个带有 2 路绑定的表单,因为我必须在构造函数中对其进行初始化。否则在加载空表单时会出错
  • 您是否尝试过将其设为接口或禁用运行时检查?
猜你喜欢
  • 1970-01-01
  • 2023-03-25
  • 2015-08-13
  • 2021-09-23
  • 2019-08-04
  • 2022-07-10
  • 1970-01-01
  • 2021-12-24
  • 2021-03-18
相关资源
最近更新 更多