michael_knight michael_knight - 1 year ago 148
AngularJS Question

AngularJS ng-click stopPropagation

I have a click Event on a table row and in this row there is also a delete Button with a click Event. When i click the delete button the click Event on the row is also fired. Here is my code.

<tr ng-repeat="user in users" class="repeat-animation" ng-click="showUser(user, $index)">
<td><button class="btn red btn-sm" ng-click="deleteUser(user.id, $index)">Delete</button></td>

How can I prevent that the showUser Event is fired when i click the delete Button in the table cell?

Answer Source

ngClick directive (as well as all other event directives) creates $event variable which is available on same scope. This variable is a reference to JS event object and can be used to call stopPropagation():

  <tr ng-repeat="user in users" ng-click="showUser(user)">
      <button class="btn" ng-click="deleteUser(user.id, $index); $event.stopPropagation();">


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download