I am currently learning Angular and encountering some challenges. I apologize if my terminology is not accurate; I hope you can still follow along.
In my HTML, I have a click event that selects a data row. My goal is to assign this selected data to a variable based on a specific model I've created. The click event successfully returns the chosen data and the model works fine in other instances. However, I'm struggling to assign the row data to the strongly-typed array variable in this case.
Here is how I declared the variable:
public selectedItem: thisModel[];
This is the latest version of the method I attempted to use for assigning the selected row values to the selectedItem variable:
getItemInfo(row: any[]){
this.selectedItem = [];
var selectedRow = row[0];
this.selectedItem[0].Description= selectedRow.Description;
this.selectedItem[0].StartDate= selectedRow.StartDate;
this.selectedItem[0].EndDate= selectedRow.EndDate;
}
Additionally, here is the model that I imported into the component:
export class thisModel {
UnitCode: number;
Description: string;
StartDate: Date;
EndDate?: Date;
}
Unfortunately, instead of assigning the row values to the variable, I receive an error in the console stating: Cannot set Description property of undefined.
I have tried various versions of this method but keep encountering the same issue. Can anyone point out where I might be making a mistake?
Thank you to everyone who provides assistance.