I am creating an image gallery with a list of images using Angular 4.3.0. Images are loaded as background images in figure
tags. Not in img
tags. The image list is resized to a smaller dimension and those are used to populate the gallery. In case the resized image is not available, the use case is to load the original image.
If original image is not available, no-image.png/jpg
will be loaded. I have seen solutions where angular directive is created to handle image load failure in src
attribute of img
tags. At this moment, I cannot change figure
tags to img
tags too due to design and time constraints. What I did was as follows.
<figure [ngStyle]="{'background-image':
'url(' + resizedImages[i] + '),
url(' + originalImages[i] + '),
url(' + noImageUrl + ')'}"
></figure>
The problem with this is if all 3 images are available, they all are loaded. So, if there are 20 images, there will be 60 image load calls. What I want to achieve is to load the original image and no-image only if the resized image is not available. Similarly, also to load the no-image only if both the resized image and original image are not available.