Okay, so I solved my problem. First of all, @Vladimir, you're totally right -- back-img was a directive my colleague wrote, which obscured the solution to me for a while.
What I've done is write a really simple directive that calls a $scope-bound function on the img's load event. My controller counts the number of images that have loaded, and once enough images have loaded, it removes the loading indicator and shows the list of images. Here's a summary of the code:
My directive:
app.directive('loadedImage', function($parse) { return { restrict: 'A', scope: true, link: function(scope, element, attrs) { element.bind("load", function(event) { var invoker = $parse(attrs.loadedCallback); invoker(scope); }); } } });
Within the element:
<img ng-src='{{ item.large }}' loaded-image loaded-callback="imageLoaded(r.id)">
And finally, within the controller:
$scope.numLoaded = 0; $scope.showLoading = true; $scope.showImages = false; $scope.imageLoaded = function(id) { $scope.numLoaded++; if ($scope.numLoaded > 9) { $scope.showLoading = false; $timeout(function() { $scope.showImages = true; }, 500) //show images once loading indicator has faded away }; };
I'm not sure this is the right approach, but it reliably works for me!
back-imgis a directive my colleague wrote that I needed to get rid of in order to move forward :)