cachaito
5/25/2017 - 2:10 PM

Nice way for watching mouse events in directives

app.directive(function($document) {
  var onDocumentClick = function(event) {
    var isChild = element.find(event.target).length > 0;
    
    if (!isChild) {
      scope.openFilterFlag = false;
      scope.$apply();
    }
  }
  
  $document.on('click', onDocumentClick);
  
  element.on('$destroy', function() {
      $document.off('click', ondocumentClick);
  });
});