Skip to content

Commit 72db89b

Browse files
fix: remove elements appended to body in ngf-select on $destroy
If the directive is added to something other than a file input, it adds file input elements to the document body. Since these are outside of the element the directive is applied to, they aren't automatically removed at the end of its life. The cleanup code for these elements already existed, but it was only being called once when the directive was first applied, and wasn't doing anything. Now it will be called on $destroy, and the file elements are correctly removed
1 parent cbbec3a commit 72db89b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/select.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,20 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
227227
angular.forEach(unwatches, function (unwatch) {
228228
unwatch();
229229
});
230+
cleanUpGeneratedElems();
230231
});
231232

232-
$timeout(function () {
233-
for (var i = 0; i < generatedElems.length; i++) {
234-
var g = generatedElems[i];
235-
if (!document.body.contains(g.el[0])) {
236-
generatedElems.splice(i, 1);
237-
g.ref.remove();
233+
function cleanUpGeneratedElems() {
234+
$timeout(function () {
235+
for (var i = 0; i < generatedElems.length; i++) {
236+
var g = generatedElems[i];
237+
if (!document.body.contains(g.el[0])) {
238+
generatedElems.splice(i, 1);
239+
g.ref.remove();
240+
}
238241
}
239-
}
240-
});
242+
});
243+
}
241244

242245
if (window.FileAPI && window.FileAPI.ngfFixIE) {
243246
window.FileAPI.ngfFixIE(elem, fileElem, changeFn);

0 commit comments

Comments
 (0)