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