在Angular中获取未定义错误的错误属性

时间:2019-05-14 18:48:42

标签: angular

我已经声明了一个对象并为其赋值。我在angular 7应用程序中收到未定义的错误ID。对象LegacyStrategyTypeSelectedItem未定义

 public LegacyStrategyTypeSelectedItem: {Id: number, Name: string };

分配值

this.LegacyStrategyTypeSelectedItem.Id = this.ClassificationOverrideDetails.ClassificationEntities.find(x=> x.ID == selectedClassficationId).LegacyStrategyId;

1 个答案:

答案 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 
};