submitTCtoDB(updateTagForm:any){
for(let i=0;i<this.selectedFileList.length;i++){
let file=this.selectedFileList[i];
this.readFile(file, function(selectedFileList) {
this.submitTC(updateTagForm,selectedFileList);
});
}
}
}
readFile(file, callback){
let fileReader: FileReader = new FileReader();
fileReader.onload= () => {
this.fileContent=fileReader.result;
if(this.fileContent.indexOf("END DATA | BEGIN RESULTS") != -1){
alert("Multiple testcases found in "+file.name+" file. Please separate/save testcases in Calc Builder. Then reimport");
const index: number = this.selectedFileList.indexOf(file);
if (index > -1) {
this.selectedFileList.splice(index, 1);
console.log(file.name+"removed from the list");
}
}
fileReader.readAsText(file);
}
callback(this.selectedFileList);
}
submitTC(updateTagForm:any,selectedFileList){
//process the selectedFileList came after the readFile has finished erading the files
}
i am seeking guidance on how to properly execute the submitTC function only after the fileReader completes reading the files. I am unsure about the implementation of the readFile() callback. Any assistance in writing the correct logic for this scenario would be greatly appreciated. Flow: When user triggers submitTCtoDB, the function is called which then initiates the process where readFile reads the files, removes any unwanted elements, and returns the refined selectedFileList. Finally, submitTC takes this list and continues with its processing.
Please lend your expertise in solving this issue.