Skip to content

Commit

Permalink
Check if container element exists before removing
Browse files Browse the repository at this point in the history
  • Loading branch information
vickramravichandran authored and vickramravichandran committed Dec 11, 2016
1 parent 9196857 commit f77fddd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions angular-datepicker-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,13 @@
});

// cleanup on destroy
scope.$on('$destroy', function () {
ctrl.empty();
ctrl.container.remove();
var destroyFn = scope.$on('$destroy', function () {
if (ctrl.container) {
ctrl.container.remove();
ctrl.container = null;
}

destroyFn()
});

function _documentKeyDown(e) {
Expand All @@ -182,6 +186,11 @@
return;
}

// no container. probably destroyed in scope $destroy
if (!ctrl.container) {
return;
}

// hide the active calendar if user clicks anywhere away from the dropdown list
var offset = ctrl.container[0].getBoundingClientRect();
var isMouseAwayFromActiveContainer = false;
Expand Down

0 comments on commit f77fddd

Please sign in to comment.