RevillWeb / angular-preload-image

A simple AngularJS module to make it easy to pre-load images.
MIT License
70 stars 29 forks source link

Event listeners not properly cleaned up #14

Open nirdil opened 7 years ago

nirdil commented 7 years ago

When you create the new image in the preLoader service you attach the 'load' and 'error' event handlers. As far as I know (and tested), these listeners need to be cleaned up otherwise you'll be left with a leak. Something like this worked for me:

var preloaderImage = angular.element(new Image());
preloaderImage.on('load', function () {
      preloaderImage.off();
      successCallback();
}).on('error', function () {
      preloaderImage.off();
      errorCallback();
}).attr('src', url);