I've been struggling since a day on this issue. I want to create this kind of situation:
<img [src]="userdp | async" />
in component.ts file I want to have this line only:
this.userdp = this._userService.getUserDp();
in the getUserDp(), here's the code:
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);
}
});
}
Promise is not waiting for the reader to load in EventListener, any immediate return statement gives the intended result, the line in bold is the main data to be returned.
Thanks