Skip the $ event needed for ng-click

I am new to AngularJS and am learning event handlers. I am moving on to the existing code base and have no idea why it $eventis being transmitted. This is what html looks like

<p><a ng-click="packBtnClick($event)" href="#" title="">[[btnAction]]</a></p>

And in the controller

$scope.packBtnClick = function($e){
  $e.preventDefault();
  if($scope.packAvailable){
     addPackIntoCart();
   }
  else{
    //some other code. 
 };

The sole purpose of passing in an event here is behavior preventDefault.
My question is: do I really need to go in $event?

+4
source share
1 answer

This is necessary if you want to call preventDefault and otherwise unnecessary. If you do not need to call something open with $event, you can safely delete it, since not passing it will not interfere with the event.

$event . jQuery, jQuery, - jqLite. . jqLite , , .

+3

All Articles