How can I make an AngularJS directive to stopPropagation?

I’ve used this way: Created a directive: .directive(‘stopEvent’, function () { return { restrict: ‘A’, link: function (scope, element, attr) { if(attr && attr.stopEvent) element.bind(attr.stopEvent, function (e) { e.stopPropagation(); }); } }; }); that could be used this way: <a ng-click=’expression’ stop-event=”click”> This is more generic way of stopping propagation of any kind of events.

What’s the difference between event.stopPropagation and event.preventDefault?

stopPropagation prevents further propagation of the current event in the capturing and bubbling phases. preventDefault prevents the default action the browser makes on that event. Examples preventDefault $(“#but”).click(function (event) { event.preventDefault() }) $(“#foo”).click(function () { alert(“parent click event fired!”) }) <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <div id=”foo”> <button id=”but”>button</button> </div> stopPropagation $(“#but”).click(function (event) { event.stopPropagation() }) $(“#foo”).click(function () … Read more