【问题标题】:NgRx 8 - Detected unserializable state for classNgRx 8 - 检测到类的不可序列化状态
【发布时间】:2019-08-26 19:38:02
【问题描述】:

我知道 NgRx 喜欢该州的普通对象,但为什么不喜欢这种呢?

export class EventRecord {
  Id = -1;
  Title = "";

  private occurred?: string = undefined;
  get OccurredDate(): string {
    return this.occurred ? this.occurred : "";
  }
  set OccurredDate(value: string) {
    const mValues = moment(value);
    if (mValues.isValid()) {
      this.occurred = mValues.toISOString();
    } else {
      throw Error("Invalid date value");
    }
  }

  PictureUri?: string;
}

这里有什么不可序列化的?

【问题讨论】:

    标签: angular ngrx ngrx-store


    【解决方案1】:

    我认为问题在于您不能序列化一个也附加了行为的类(getter 和 setter)。 您只能序列化纯数据类(没有行为的类,只有普通属性)。

    【讨论】:

      猜你喜欢
      • 2021-08-03
      • 2021-11-11
      • 1970-01-01
      • 2019-12-08
      • 1970-01-01
      • 2021-06-19
      • 2021-12-06
      • 2018-08-14
      • 1970-01-01
      相关资源
      最近更新 更多