Even though I defined and initialized my array twice, I am encountering a runtime error: "ERROR TypeError: Cannot read property 'length' of undefined."
I have double-checked the definition of the array in my code, but Angular seems to be playing tricks on me. I have attempted various solutions such as changing the syntax to "filesToUpload && filesToUpload?.length > 0," yet Angular is still not functioning correctly in my opinion.
Here is an excerpt from the component.html file:
<ng-container *ngIf="undefined !== filesToUpload && filesToUpload.length > 0">
<button (click)='uploadImages()'
class="btn btn-success"
type="button">
<i class="fas fa-upload"></i>Upload
</button>
<button (click)='cancelUpdate()'
class="btn btn-danger"
type="button">Cancel</button>
</ng-container>
The corresponding component.ts file looks like this:
export class ImageGalleryUploadComponent implements OnInit
{
filesToUpload: File[] = [];
ngOnInit() {
this.filesToUpload = []
}
}
Could this be an issue with Angular itself or possibly related to the component lifecycle?