mrded mrded - 7 months ago 26
AngularJS Question

How can I catch outbound link click on an Angular 1.x website?

I'm trying to catch link clicks to external websites, to track them later.

Something like

<a href="#" ng-click="click()">foo</a>
but across all DOM tree.

Most of a content is coming from external REST server, thus I cannot use



what you can do is write a directve named a

angular.module('tracking', [])
.directive('a', function() {
  return {
    restrict: 'E'
    link: function(scope, element, attrs) {
      element.on('click', function() {
        if ( == outside-target)
        //your logic

important logical part would be

     if ( == outside-target)
        //your logic