I am not able to access a class variable which is set inside FileReader onloadend method.
Here is my code:
analyzeData(){
let file = this.fileRestful[0];
let fileReader: FileReader = new FileReader();
fileReader.onloadend = () => {
this.fileContent= fileReader.result as string;
}
fileReader.readAsText(file);
console.log(this.fileContent)
}
I have tried 3 methods till now but none worked. Following are they:
fileReader.onloadend = () => { this.fileContent= fileReader.result as string; }
fileReader.onloadend = function(e) = { this.fileContent= fileReader.result as string; }.bind(this)
let self = this; fileReader.onloadend = function(e) = { self.fileContent= fileReader.result as string; }
I have already seen most of the solution but none worked for me. Please let me know where I am making error. Thank you.