Created
October 13, 2014 15:54
-
-
Save shawncarr/31cd4ab95426422939d3 to your computer and use it in GitHub Desktop.
Angular - Prevent default actions on A links with a ngClick or blank href
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app').directive('href', function() { | |
return { | |
restrict: 'A', | |
compile: function(element, attr) { | |
return function(scope, element) { | |
if (attr.ngClick || attr.href === '' || attr.href === '#') { | |
element.on('click', function(e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
}); | |
} | |
}; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment