Reputation: 491
I have this ion-img tag
<ion-avatar [ngClass]="cssClass">
<ion-img
[src]="avatar"
(ionError)="failedImageLoad($event)"></ion-img>
</ion-avatar>
And i need to send an error event when the image failed to load, this (ionError)
event is in the documentation of the ion-img tag, but it doenst work, and the other events handler are working fine, someone knows any other event handler for error ?
Upvotes: 2
Views: 4878
Reputation: 39
fallbackUrl = 'assets/img/fallback-image.png';
<ion-img [src]="user.userMg" (ionError)="user.userMg = fallbackUrl"></ion-img>
Upvotes: 0
Reputation: 41
My solution for image load error
<img class="avatar" [src]="merchant.logo_url" (error)="errorImage(img)" #img />
errorImage(img) {
img.src = '../../../../../../assets/svg-icons/022-menu.svg'
}
Upvotes: 2
Reputation: 13125
Seems you have something else going on as it's working for me:
<ion-img src="notfound.png" (ionError)="onError()"></ion-img>
With this handler in the codebehind:
onError() {
console.log("IMG ERROR");
}
And this output:
Are you sure you have got the correct name for your error handler function?
failedImageLoad()
Based on your comment you are dealing with a 403 error.
I looked at the code and the ionError
is really just a wrapper for the html img onerror
event.
This is defined on mdn:
So it seems that it should trigger the error.
Just to be sure: you mention two separate files this time, which wasn't in your original question. Have you put the image handler in both of them?
Upvotes: 0