How To PreventDefault On ng-click In AngularJS

Here’s a handy AngularJS, trick which allows you to prevent default behavior on ng-click event.

All you need to do is pass the $event parameter to your function inside the ng-click.

<button ng-click="saveData($event)">Save</button>

And receive that parameter inside your function within your controller and preventDefault() method.

$scope.saveData = function($event) {

Must Read: How To Show Validation Errors On Submit In Angularjs?

Leave a Comment.