Created
December 18, 2015 15:06
-
-
Save anaumov/07943d43fa92a223a93d to your computer and use it in GitHub Desktop.
AutoClose 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
export function AutocloseDirective ($document, $timeout) { | |
'ngInject'; | |
let directive = { | |
restrict: 'A', | |
scope: { visible: "=mdAutoclose" }, | |
link: (scope) => { | |
let close = () => { | |
scope.$apply(() => {scope.visible = false;}); | |
}; | |
scope.$watch('visible', (val) => { | |
if (val) { | |
$timeout(() => {$document.on('click', close);}); | |
} else { | |
$document.off('click', close) ; | |
} | |
}); | |
} | |
}; | |
return directive; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment