1window.angular && (function(angular) { 2 'use strict'; 3 4 angular.module('app.common.directives').directive('toggleFlag', [ 5 '$document', 6 function($document) { 7 return { 8 restrict: 'A', 9 link: function(scope, element, attrs) { 10 function elementClick(e) { 11 e.stopPropagation(); 12 } 13 14 function documentClick(e) { 15 scope[attrs.toggleFlag] = false; 16 scope.$apply(); 17 } 18 19 element.on('click', elementClick); 20 $document.on('click', documentClick); 21 22 // remove event handlers when directive is destroyed 23 scope.$on('$destroy', function() { 24 element.off('click', elementClick); 25 $document.off('click', documentClick); 26 }); 27 } 28 }; 29 } 30 ]); 31})(window.angular); 32