我想将值system
更新为对象telecom
,但是在此阶段它显示此错误
无法将对象'[object]分配为只读属性'system' 对象]'
this.organization.telecoms.forEach((telecom: Telecom) =>
telecom.system = 'test'
);
console.log(this.organization);
export class Organization {
public effectiveDate?: EffectiveDate;
public identifiers?: IdentifierOrg[];
public kilometerZones?: KilometerZone[];
public telecoms?: Telecom[];
}
export class Telecom {
public system?: string;
public value?: string;
}
答案 0 :(得分:-1)
尝试初始化课程。
从here签出此应用
export class AppComponent {
organization: Organization;
constructor() {
this.organization = new Organization();
this.organization.telecoms = [
{
system: 'foo',
value: 'val'
},
{
system: 'foo2',
value: 'val2'
},
{
system: 'foo3',
value: 'val3'
}
]
this.organization.telecoms.forEach((telecom: Telecom) =>
telecom.system = 'test'
);
console.log(this.organization);
}
}
export class Organization {
public telecoms?: Telecom[];
}
export class Telecom {
public system?: string;
public value?: string;
}