Jessica Illy Jessica Illy - 3 months ago 50
AngularJS Question

cache image using angularjs without plugin

<img src="{{selected}}.jpg"/>

my selected model is dynamic, I can load the img proper but how to cache every single photo because I notice there's a delay when I apply new value to


The easiest way would be to do it in your controller:

angular.module('app').controller('myController', function(images) {
    var preload = {};
    angular.forEach(images, function(image, i) {
        preload[i] = new Image()
        preload[i].src = "" + image + ".jpg";