【问题标题】:Immutable arrays after upgrading angular to 11将 Angular 升级到 11 后的不可变数组
【发布时间】:2021-04-15 16:23:27
【问题描述】:

我刚刚将 Angular 从 6 升级到 11,并将 typescript 升级到 4.1.5。 我在更改数组中任何对象的属性时遇到问题。结果报错

core.js:6150 ERROR TypeError: Cannot assign to read only property 'active' of object '[object Object]'

我要更改的对象是:

  export interface Agreement {
    active: boolean;
    ...
}

此外,当我尝试向任何列表添加内容时,我会收到此错误:

ERROR TypeError: Cannot add property 4, object is not extensible
at Array.push (<anonymous>)

我是否缺少任何全局配置属性?

【问题讨论】:

    标签: angular11 typescript4.0


    【解决方案1】:

    我只是像这样创建了给定字段的副本:

    field = JSON.parse(JSON.stringify(field))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 2019-11-07
      • 1970-01-01
      • 2020-03-21
      • 2021-03-03
      • 1970-01-01
      相关资源
      最近更新 更多