In my angular(typescript)
application, I have an interface defined as follows:
export interface PartnerCnic{
id: string;
shipperRegCnicFront: File;
shipperRegCnicBack: File;
}
Within my component, I have initialized an empty array for this interface like so:
partnerCnics: PartnerCnic[] = [];
Now, I need to insert a value into a specific index of this interface array. Since the array starts off empty and I want to populate it dynamically, I have created a fileUpload
function where each time a user selects a file, I attempt to update the array accordingly:
fileUpload(index: number, key: string, dropFile: File){
this.partnerCnics[index][key] = dropFile;
}
However, when I run this function, I encounter the following error message:
Cannot set property 'shipperRegCnicFront' of undefined
So, how can I successfully insert a value at a specific index in my TypeScript interface array?