onDocumentClick not correctly de-registered
mihneasim opened this issue · 0 comments
mihneasim commented
Bug description:
Dropdown opens and closes when re-entering a view which renders ui-select. Root cause: onDocumentClick is not correctly de-registered.
Link to minimally-working plunker that reproduces the issue:
Version of Angular, UI-Select, and Bootstrap/Select2/Selectize CSS
Angular: 1.6
UI-Select: 0.19.8
Bootstrap/Select2/Selectize CSS (if applicable): "angular-ui-bootstrap": "2.5.0"
I changed the code accordingly in select.js
for debugging purposes:
function onDocumentClick(e) {
console.log('onDocumentClick:', e.target, '$scope.open:', $select.open);
..
if i enter/exit 4 times the view which uses ui-select, and i click once in an element, i will get 3 onDocumentClick
triggered for (e.target) and once for the actual clicked element, see screenshot -
which is not what one would expect given that we do de-register the delegated event handler on scope $destroy:
$document.on('click', onDocumentClick);
scope.$on('$destroy', function() {
$document.off('click', onDocumentClick);
});