Skip to content

Commit f9b891c

Browse files
author
Niels Dequeker
committed
2 parents c7dbddb + 45e3115 commit f9b891c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

source/directives/uiTreeNode.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,19 @@
411411
element.bind('touchend touchcancel mouseup',function(){$timeout.cancel(dragTimer);});
412412
};
413413
bindDrag();
414-
415-
angular.element($window.document.body).bind("keydown", function(e) {
416-
if (e.keyCode == 27) {
417-
scope.$$apply = false;
418-
dragEnd(e);
419-
}
414+
415+
var keydownHandler = function(e) {
416+
if (e.keyCode == 27) {
417+
scope.$$apply = false;
418+
dragEnd(e);
419+
}
420+
};
421+
422+
angular.element($window.document.body).bind("keydown", keydownHandler);
423+
424+
//unbind handler that retains scope
425+
scope.$on('$destroy', function () {
426+
angular.element($window.document.body).unbind("keydown", keydownHandler);
420427
});
421428
}
422429
};

0 commit comments

Comments
 (0)