Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested ng-click & $event.stopPropagation()

I'm trying to cancel propagation inside a nested ng-click event.

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

Relevant View Code:

<tbody>
  <tr ng-click="goTo(1)">
    <td class="col-md-1">{{ client.code }}</td>
    <td class="col-md-5">{{ client.name }}</td>
    <td class="col-md-2">{{ client.telephone }}</td>
    <td class="col-md-2">{{ client.fax }}</td>
    <td class="col-md-2"><a href="mailto:{{client.email}}" ng-click="cancel($event)">{{client.email}}</a></td>
  </tr>
</tbody>

Here's a plunker: http://plnkr.co/edit/dxgfK41Dp1Gs2DCmeFcw?p=info

Why doesn't it work?

like image 546
Sean Avatar asked Feb 14 '26 18:02

Sean


1 Answers

It's not working because $event is undefined if you don't pass $event from the view:

Add this to your view:

<td class="col-md-2"><a href="mailto:{{client.email}}" ng-click="cancel($event)">{{client.email}}</a></td>

Here's your updated plunkr with propagation stopped: http://plnkr.co/edit/ywvPcO01C0fgzvpxRnf9?p=info

like image 56
yvesmancera Avatar answered Feb 16 '26 15:02

yvesmancera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!