Skip to content

Instantly share code, notes, and snippets.

@shawncarr
Created October 13, 2014 15:54
Show Gist options
  • Save shawncarr/31cd4ab95426422939d3 to your computer and use it in GitHub Desktop.
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
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