Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3 Image lazy loader

I am developing ionic application which uses external image files. These images are loading in elements such as ion-card,ion-item,ion-slides. I need a spinner or some kind of technique to show until the image successfully.

I tried image caching plugins but it wasn't success.

Looking forward a better solution.

Thank you.

like image 871
Deemantha Avatar asked May 31 '26 18:05

Deemantha


1 Answers

Define a loading picture in your js e.g.

loadingAnimation = "../../assets/img/loadingAnimation.gif";

Then use the || operator when setting the source in html:

<img [src]='{{ (yourActualPicture) || (loadingAnimation ) }}'/>

This way the loading animation will be shown until the actual picture has been downloaded.

On a side-note: You might want to have a look at Ionic's Spinner component https://ionicframework.com/docs/api/components/spinner/Spinner/

like image 195
Rizz Avatar answered Jun 02 '26 06:06

Rizz