Skip to content

Instantly share code, notes, and snippets.

@catindev
Last active May 3, 2016 03:14
Show Gist options
  • Save catindev/11a6ebbfcb5c2b855f0ab56f30b7cae3 to your computer and use it in GitHub Desktop.
Save catindev/11a6ebbfcb5c2b855f0ab56f30b7cae3 to your computer and use it in GitHub Desktop.
#AngularJS Click outside directive
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