Last active
May 3, 2016 03:14
-
-
Save catindev/11a6ebbfcb5c2b855f0ab56f30b7cae3 to your computer and use it in GitHub Desktop.
#AngularJS Click outside directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function clickOutside( $document ) { | |
const isOutSide = (el, evt) => el !== evt.target && !el[0].contains( evt.target ); | |
const link = ( scope, el ) => $document.on( | |
'click', | |
evt => { | |
if ( isOutSide(el, evt) ) scope.$eval( scope.clickOutside ); | |
} | |
); | |
const directive = { | |
restrict: 'A', | |
scope: { clickOutside: '&' }, | |
link | |
}; | |
return directive; | |
} | |
export default clickOutside; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment