I created a custom directive for selecting time using two blocks. The challenge is detecting the target event on specific blocks within the directive's template. Directive Template:
<div class='time-picker-container'>
<div class='block1' ng-click='show()'>1</div>
<div class='block2' ng-show='selectVisible'>2</div>
</div>
JS:
scope.selectVisible = false;
scope.show = function() {
scope.selectVisible = !scope.selectVisible;
}
$rootScope.$on('documentClicked', function(inner, target) {
// attempting to hide div.block2 if the user clicks outside the block
});
Main concept: when the user clicks on the document, outside of div.block2, the block disappears. If the user clicks inside div.block2, the block remains visible.
Function execution:
angular.element(document).on('click', function(e) {
$rootScope.$broadcast('documentClicked', angular.element(e.target));
});