question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ionImgDidLoad fires before before inner img load event

See original GitHub issue

Bug Report

Ionic version:

[x] 4.x

Current behavior:

I want to display a placeholder image while the ion-img is loading using ion-img component and binding to the ionImgDidLoad event. the event would fire as soon as the image start loading. Expected behavior: from its name ionImgDidLoad event must be fired after the image have been completely loaded.

Steps to reproduce:

Related code: https://stackblitz.com/edit/ionic-4-template-fewyal?embed=1&file=src/app/home/home.page.html https://stackblitz.com/edit/ionic-4-template-fewyal?embed=1&file=src/app/home/home.page.html

<ion-content padding>
    <ion-img class="placeholder-img" 
      src="https://via.placeholder.com/150"
      [style.display]="loaded ? 'none' : 'unset'"
    ></ion-img>

    <ion-img class="full-img"
      [src]="'https://picsum.photos/5000/5000'"
      [style.opacity]="loaded ? 1 : 0"

      (ionImgDidLoad)="loaded = true"
      ></ion-img>
</ion-content>

Other information: the issue is related to this part of the ion-img source private load() { this.loadSrc = this.src; this.ionImgDidLoad.emit(); } the event is triggered as soon as the src attribute is set, i think this event must be frenamed to ionImgStartLoad, and add another event ionImgDidLoad that is fired when the inner img load completed. Ionic info:


Ionic:

   ionic (Ionic CLI)             : 4.10.3 (C:\Users\jahmani\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.0.1
   @angular-devkit/build-angular : 0.7.5
   @angular-devkit/schematics    : 0.7.5
   @angular/cli                  : 7.3.1
   @ionic/angular-toolkit        : 1.4.0

Cordova:

   cordova (Cordova CLI) : not installed
   Cordova Platforms     : not available
   Cordova Plugins       : not available

System:

   NodeJS : v10.15.1 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
liamdebeasicommented, Mar 5, 2019

Hi @jahmani,

Thanks for the additional info! I am able to reproduce what you are describing. Thanks for the bug report – we will look into this!

0reactions
ionitron-bot[bot]commented, May 31, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ionImgDidLoad fires before before inner img load event #17652
It's a bug in the ion-img component code. It must wait the inner image load event before emiting this Event - ionImgDidLoad -...
Read more >
javascript - *ngFor with multiple image tags - how to know ...
This fails when the images are shuffled and if an image is already loaded, then the event won't fire.. In that case this...
Read more >
7731 - Image onload event does not fire when loading an ...
Fire load event for an image even if it was the last image we loaded successfully. ... to reset the current image stored...
Read more >
5. Building App Logic - Events Handling - Appery.io
Fires when the component routing from the page is about to animate and gets called directly before the transition away from the current...
Read more >
ion-img Tag - Ionic Framework
Img is a tag that will lazily load an image whenever the tag is in the viewport. This is extremely useful when generating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found