I have a model defined like this :
export interface AddAlbumeModel {
name: string;
gener: string;
signer: string;
albumeProfile:any;
albumPoster:any;
tracks:TrackMode[];
}
export interface TrackMode {
trackNumber: number;
trackName: string;
trackProfile: any;
trackPoster:any;
trackFile: any;
}
Now, I'm trying to add tracks
using the following code :
let addModel = {} as AddAlbumeModel;
for (let index = 0; index < this.addAlbumFG.controls['tracks']['controls'].length; index++) {
const item= this.addAlbumFG.controls['tracks']['controls'][index]['controls'];
if(!addModel.tracks){
addModel.tracks = [];
}
addModel.tracks.push({
trackFile:item.trackFile.value['files'][0],
trackNumber:item.trackNumber.value,
trackName:item.trackName.value,
trackPoster:item.trackPoster.value['files'][0],
trackProfile:item.trackProfile.value['files'][0]
})
}
However, I'm encountering the following error message :
ERROR TypeError: Cannot read property 'push' of undefined
Can someone help me find a solution for this issue?