我已经声明了一个对象并为其赋值。我在angular 7应用程序中收到未定义的错误ID。对象LegacyStrategyTypeSelectedItem未定义
public LegacyStrategyTypeSelectedItem: {Id: number, Name: string };
分配值
this.LegacyStrategyTypeSelectedItem.Id = this.ClassificationOverrideDetails.ClassificationEntities.find(x=> x.ID == selectedClassficationId).LegacyStrategyId;
答案 0 :(得分:0)
您定义了对象,但没有值
因此您需要先为this.LegacyStrategyTypeSelectedItem
分配一个值
例如
public LegacyStrategyTypeSelectedItem: {Id: number, Name: string } = { Id : null , Name: null}
或
this.LegacyStrategyTypeSelectedItem = {
Id: this.ClassificationOverrideDetails.ClassificationEntities.find(x=> x.ID == selectedClassficationId).LegacyStrategyId ,
Name: null
};