danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.6k forks source link

generatedElems are not cleaned up on $destroy #1923

Open avohmincevs opened 7 years ago

avohmincevs commented 7 years ago

generatedElems array gets cleaned up whenever the ngf-select is initialized through the use of $timeout.

L32-L240

  $timeout(function () {
      for (var i = 0; i < generatedElems.length; i++) {
        var g = generatedElems[i];
        if (!document.body.contains(g.el[0])) {
          generatedElems.splice(i, 1);
          g.ref.remove();
        }
      }
    });

This leaves the generatedElems detached from the DOM whenever ngf-select is destroyed and is not subsequently recreated.

Perhaps it is possible to move the logic into $destroy handler that is right above $timeout?

L225-L230

    scope.$on('$destroy', function () {
      if (!isInputTypeFile()) fileElem.parent().remove();
      angular.forEach(unwatches, function (unwatch) {
        unwatch();
      });
    });