Last Updated: February 25, 2016
·
5.726K
· 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?

AngularJS pages are long-lived browser apps with the same script risk as a newer single-page app. Third-party code in the template can read forms and values rendered on the page.

Security insights from Cside