I am using ng-src in <img> tag, but whenever I am changing the ng-src on clicking the next or previous button, it loads the image in the browser (checked in network tab), although all the images are already loaded. So clicking on the next or previous button does not give a smooth experience and image firstly downloaded again by the browser and then rendered.
Can someone help me to solve this issue so that images which are already loaded by browser need not be loaded by making a new HTTP request.
<div class="slider" ng-style="{'width': ctrl.options.width,'height':ctrl.options.height}">
<img class="materialboxed mainImage"
ng-style="{'width': ctrl.options.width,'height':ctrl.options.height}"
ng-src="{{ctrl.data[ctrl.currentImageIndex]}}">
<i class="material-icons icon-arrow_left"
ng-if="ctrl.displayLeftArrow"
ng-click="ctrl.prevImg()">keyboard_arrow_left
</i>
<i class="material-icons icon-arrow_right"
ng-if="ctrl.displayRightArrow"
ng-click="ctrl.nextImg()">keyboard_arrow_right
</i>
</div>
Here is the array of images that I am using:
[
'https://static.pexels.com/photos/257360/pexels-photo-257360.jpeg',
'https://lorempixel.com/580/250/nature/1',
'https://lorempixel.com/580/250/nature/2',
'https://lorempixel.com/580/250/nature/3',
'https://lorempixel.com/580/250/nature/4',
]
Controller is here:
preloader.preloadImages($scope.data);
self.init = function () {
self.currentImageIndex = 0;
checkArrowVisibility();
};
self.prevImg = function () {
self.currentImageIndex--;
checkArrowVisibility();
};
self.nextImg = function () {
self.currentImageIndex++;
checkArrowVisibility();
};
$scope.data holds the images array