AngularJS Example

for http://stepansuvorov.com/blog/

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div ng-controller="mainCtrl">
    <button ng-click="dosomething($event)" custom>BUTTON</button>
</div>

JavaScript

var app = angular.module('app', []);


app.controller('mainCtrl', function ($scope) { 
    $scope.dosomething = function($event){
        $event.stopPropagation();
        $event.preventDefault();
        alert('here');
        
        if (true) {
            $event.stopNextHandler = true;
        }
    }

});


app.directive('custom', function(){
    return {
        restrict:'A',
        link: function(scope, element){
            element.bind('click', function($event) {
                if ($event.stopNextHandler !== true) {
                    alert('want to prevent this');
                }
            });            
        }
    }

});