I have this function ror convert file to base64 for show file.
ConvertFileToAddress(event): string {
let localAddress: any;
const reader = new FileReader();
reader.readAsDataURL(event.target['files'][0]);
reader.onload = (e) => {
localAddress = e.target['result'];
};
return localAddress;
}
And use it not components like this:
this.coverSrc=this.localization.ConvertFileToAddress(event);
But when log to the console the this.coverSrc it shows me undefined.
When I log in this bracket:
reader.onload = (e) => {
localAddress = e.target['result'];
};
It show the value of base64 but when I log the localAddress outside of bracket it shows me undefined.
How can I return the value of function and use it in other components?