I'm showing a profile image in an Ionic view like this:
<ion-avatar>
<img [src]="profileImageUrl()">
</ion-avatar>
The image url comes from the componente script:
ionViewDidLoad() {
let email = this.storage.getLocalUser().email;
this.clientService.findByEmail(email)
.subscribe(resp => {
this.client = resp;
},
error => {
});
}
profileImageUrl() {
if (this.client) {
return `${API_CONFIG.bucketBaseUrl}/client${this.client.id}.jpg`;
}
else {
return "assets/imgs/avatar-blank.png";
}
}
Notice that I get client data in ionViewDidLoad() using a backend service call, and then provide a profileImageUrl() method that returns either the S3 file, or a local blank picture in case client data hasn't been loaded yet.
However, I'd like to also check if the S3 file actually exists. If not, I'd like to also return the local blank picture as well. How would I do this?