Skip to content

Instantly share code, notes, and snippets.

@zdenekhatak
Created October 30, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdenekhatak/79b5a144f75de195e8ae to your computer and use it in GitHub Desktop.
Save zdenekhatak/79b5a144f75de195e8ae to your computer and use it in GitHub Desktop.
(function() {
'use strict';
angular
.module('app')
.directive('preloadImages', preloadImagesDirective);
preloadImagesDirective.$inject = [];
function preloadImagesDirective() {
return {
restrict: 'A',
link: function($scope, el, attrs) {
var evaledImages = $scope.$eval(attrs.images);
if (angular.isArray(evaledImages)) {
var images = evaledImages;
} else {
var images = attrs.images.replace(/'/g, "").split(',');
}
angular.forEach(images, function(value) {
var img = new Image();
img.src = value;
});
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment