Jessica Illy
Jessica Illy

Reputation: 67

cache image using angularjs without plugin

<img src="http://assets.example.com/static/thumb_{{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 selected.

Upvotes: 0

Views: 310

Answers (2)

Shankar Gangadhar
Shankar Gangadhar

Reputation: 197

angular .module('demo', [ 'ngImageCache' ]) ;

Note: Image is loaded using javascript, content is stored in sessionStorage for next loading

Use package npm install ng-image-cache

Upvotes: 1

Blue
Blue

Reputation: 22911

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 = "http://assets.example.com/static/thumb_" + image + ".jpg";
    });
});

Upvotes: 0

Related Questions