Skip to content

Commit a53fdb0

Browse files
Bug #35 when destroying it removes all click events for the document
1 parent 5a97e47 commit a53fdb0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/scripts/directive.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
}
3737
$scope.initConfig();
3838

39-
$document.on('click', function (evt) {
40-
if ($scope.find(evt.target).length === 0) {
41-
$scope.log('Color Picker: Document Click Event');
42-
$scope.hide();
43-
}
44-
});
39+
$document.on('click', $scope.onClick);
40+
};
41+
42+
$scope.onClick = function(event) {
43+
if ($scope.find(event.target).length === 0) {
44+
$scope.log('Color Picker: Document Click Event');
45+
$scope.hide();
46+
}
4547
};
4648

4749
$scope.initConfig = function() {
@@ -418,7 +420,7 @@
418420
$scope.init();
419421

420422
$scope.$on('$destroy', function() {
421-
$document.off('click');
423+
$document.off('click', $scope.onClick);
422424
});
423425
}
424426
};

0 commit comments

Comments
 (0)