This is a pseudo code of a Directive I'm modifying. Let's assume I have the following event handlers:
<a my-link ng-click="foo()" foo-check="fooCheck"></a>
angular.module('linkModule')
.directive('mylink', function () {
return {
restrict: 'A',
scope: {
fooCheck: '='
},
link: function link ($scope, $element) {
// bar method has some vital function
// for this directive`s functionality and must be run
// ONLY if certain conditions are met.
var bar = function bar () {
console.log('Executing bar');
};
$element.on('click', function (e) {
e.preventDefault();
// Validate something here
var mustContinue = $scope.fooCheck();
if ( mustContinue ) {
bar();
} else {
// Cancel ng-click here
}
});
}
};
});
So, my question is: Can I prevent the ng-click event from being executed from the directive's link event listener?