Last Updated: February 25, 2016
·
5.721K
· adityasaxena

AngularJS stop event propagation

In AngularJS context:

If you have the following in your page,

<a ng-click="nextPage($event)">Button</a>

then in your controller, you should say

$scope.nextPage = function($event){
    $event.stopPropagation();
}

I was trying this with jquery like this:

$('selector').on('click', 'target-selector', function(e){
   e.stopPropagation();
});

This just doesn't work because the event has already fired in by the time we check for event propagation.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside