test-data component.ts
export class TestDataManagementComponent {
requirement = [] as any;
testDataFileType = "doc,docx,xls,xlsx,pdf,application/msword,application/msexcel,application/pdf";
isNotAccepted = false;
submitForm() {
var splitted = this.testDataFileType.split(",");
let payload = new FormData();
for (let i = 0; i < this.requirement.length; i++) {
payload.append('requirements', this.requirement[i]);
}
splitted.forEach(function (value) {
for(let i = 0 ; i < this.requirement.length; i++) {
if(this.requirement[i].name.split('.').pop() === value) {
this.isNotAccepted = false;
break;
}
if(this.requirement[i].name.split('.').pop() !== value) {
this.isNotAccepted = true;
break;
}
}
});
ERROR TypeError: Cannot read property 'requirement' of undefined
Please help me figure out why 'requirement' is not defined and what is the best way to check each file's extension looping through the type array at once.