Skip to content

Instantly share code, notes, and snippets.

@anaumov
Created December 18, 2015 15:06
Show Gist options
  • Save anaumov/07943d43fa92a223a93d to your computer and use it in GitHub Desktop.
Save anaumov/07943d43fa92a223a93d to your computer and use it in GitHub Desktop.
AutoClose Directive
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