I have been facing this issue for the past day and need help creating a specific scenario:
<img [src]="userdp | async" />
In my component.ts file, I want to include only this line:
this.userdp = this._userService.getUserDp();
Here is the code within the getUserDp() method:
async getUserDp() {
return await
this._http.get(APIvars.APIdomain+'/'+APIvars.GET_USER_DP, { responseType: 'blob' }).toPromise().then( image => {
if(image['type'] === 'application/json') {
return null;
}
const reader = new FileReader();
reader.addEventListener('load', () => {
**return this._dom.bypassSecurityTrustResourceUrl(reader.result.toString());**
});
}, false);
if (image) {
reader.readAsDataURL(image);
}
});
}
The promise does not wait for the reader to load in the EventListener, any immediate return statement produces the desired result. The bolded line contains the main data to be returned.
Thank you