In html
<input type="file" multiple="multiple" (change)="getFileSizeandName($event)"/>
in file.ts
I have global variable
imageStringBase64: Array<string>;
and function call when event change trigger
getFileSizeandName(args) {
let files = args.target.files;
for (let i = 0; i < files.length; i++) {
let reader = new FileReader();
reader.onload = (function (f) {
return function(e) {
console.log(e.target.result);
this.imageStringBase64 = e.target.result;
}
})(files[i]);
reader.readAsDataURL(files[i]);
}
}
}
When i use conole.log(e.target.result) in console printed stringBase64 Assign this.imageStringBase64 = e.target.result and have unexpected result, this.imageStringBase64 is undefined. How use global var in anonymous function?