How to prevent a ng click event when a tag a is disabled? - mendhak/angular-intro.js GitHub Wiki

How to prevent a ng-click event when <a> tag is disabled?

i wrote the following code, update to your needs.:

.directive('ngClick', function () {
  return {
    restrict: 'A',
    priority: 1,
    terminal: true, // this will prevent default ng-click behaviour
    link: function (scope, element, attr) {
      var clickAction = attr.ngClick; // get the current ngclick value
      var binding = element.bind('click',function () {
        if (attr.disabled==undefined) {//check if the tag is available to be clicked
          scope.$eval(clickAction) // call the event
        }
      });
      scope.$on('$destroy', function(){
        binding(); // destroy the bind we created, preventing a memory leak.
      })
    }
  };
});