Inspired heavily by this blog post. Credit for preloader code goes to Ben Nadel.
Include the preloader service in your controller:
app.controller('MyController', function($scope, preloader) {}
Pass in an array of images for the preloader:
$scope.imageLocations = [
"img/one.png",
"img/two.png",
"img/three.png",
...
];
Call the preloader.preloadImages function, passing in your array of images:
preloader.preloadImages( $scope.imageLocations )
preloader.preloadImages returns a promise, so you could also handle the promise like so:
preloader.preloadImages( $scope.imageLocations )
.then(function() {
// Loading was successful.
},
function() {
// Loading failed on at least one image.
});