0

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

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

赋值

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

1 回答 1

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 
};
于 2019-05-14T18:51:26.947 回答