|
1 | 1 | uis.directive('uiSelect', |
2 | | - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', |
3 | | - function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { |
| 2 | + ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', '$window', |
| 3 | + function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout, $window) { |
4 | 4 |
|
5 | 5 | return { |
6 | 6 | restrict: 'EA', |
@@ -206,11 +206,15 @@ uis.directive('uiSelect', |
206 | 206 | $select.clickTriggeredSelect = false; |
207 | 207 | } |
208 | 208 |
|
209 | | - // See Click everywhere but here event http://stackoverflow.com/questions/12931369 |
210 | | - $document.on('click', onDocumentClick); |
| 209 | + // See Click everywhere but here. Similar approach to http://stackoverflow.com/questions/12931369 |
| 210 | + // but using the capture phase instead of bubble phase of the event propagation. |
| 211 | + // |
| 212 | + // Using the capture phase avoids problems that araise when event.stopPropatagion() |
| 213 | + // is called before the event reaches the `document`. |
| 214 | + $window.document.addEventListener('click', onDocumentClick, true); |
211 | 215 |
|
212 | 216 | scope.$on('$destroy', function() { |
213 | | - $document.off('click', onDocumentClick); |
| 217 | + $window.document.removeEventListener('click', onDocumentClick, true); |
214 | 218 | }); |
215 | 219 |
|
216 | 220 | // Move transcluded elements to their correct position in main template |
|
0 commit comments