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.

Leave a Comment