Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ion-img onerror #16947

Closed
pickfire opened this issue Jan 3, 2019 · 5 comments · Fixed by #17134
Closed

ion-img onerror #16947

pickfire opened this issue Jan 3, 2019 · 5 comments · Fixed by #17134
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement

Comments

@pickfire
Copy link
Contributor

pickfire commented Jan 3, 2019

Feature Request

Ionic version:

[x] 4.x

Describe the Feature Request

Add support for ion-img to handle error during lazy loading. Currently only img supports onerror but ion-img does not.

onerror is useful when we want to fallback to a default image. Such as:

<ion-img [src]="image.src" (error)="this.src = 'assets/img/error.svg'"></ion-img>

Describe Preferred Solution

onerror support.

Describe Alternatives

Use img but there is no lazy loading and a lot slower.

Related Code

Additional Context

@ionitron-bot ionitron-bot bot added the triage label Jan 3, 2019
@paulstelzer paulstelzer added type: feature request a new feature, enhancement, or improvement package: core @ionic/core package and removed triage labels Jan 3, 2019
pickfire added a commit to pickfire/ionic that referenced this issue Jan 16, 2019
@touch2hussain
Copy link

any update on this feature request? it must have feature when images are dynamically loaded and not sure they exist

@pickfire
Copy link
Contributor Author

pickfire commented Mar 7, 2019

I wonder if there are any updates as well, it seems like it is merged from the pull request but I am not sure what happened and it is not included in the release as well.

@SamVerschueren
Copy link

It's not yet merged but is really blocking us.

@vitgije
Copy link

vitgije commented Mar 21, 2019

@SamVerschueren I have written a quick and dirty workaround to hook into the original 'onerror' event of the img within the shadow-root using the already available ionImgDidLoad event as I ran into the same issue. I have no idea whether this works on a device, but perhaps it could help you. I do agree with the original request where we can register an event upon the ion-img tag though.

In *.page.html:

<ion-img [src]="product.image !== '' ? product.image : ''" alt="" class="image-loading" (ionImgDidLoad)="imageLoaded($event)"></ion-img>

in *.page.ts:

imageLoaded(event) {
  // Register the onerror event on the image in case of a 404
  let img = event.srcElement.shadowRoot.children[1];
  img.onerror = () => { img.src = '/assets/no-media.png'; };
  event.srcElement.className = event.srcElement.className.replace('image-loading', '');
}

@ionitron-bot
Copy link

ionitron-bot bot commented Apr 26, 2019

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Apr 26, 2019
kiku-jw pushed a commit to kiku-jw/ionic that referenced this issue May 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants