Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable parent ng-click?

Tags:

angularjs

I have HTML structure with ng-click:

<div ng-click="parent()">
  <div ng-click="d"></div>
</div>

How I can disable outside ng-click="parent()" if I do ng-click="d"

like image 847
Muhad Avatar asked Sep 26 '15 16:09

Muhad


2 Answers

Use the stopPropagation method on the angular $event object:

<div ng-click="parent()">
  <div ng-click="d(); $event.stopPropagation();"></div>
</div>

Or pass the $event object as an argument of the ng-click method, and call stopPropagation in the method:

<div ng-click="parent()">
  <div ng-click="d($event)"></div>
</div>

In d:

$scope.d = function (event) {
    // ...
    event.stopPropagation();
}
like image 66
Michael P. Bazos Avatar answered Oct 22 '22 05:10

Michael P. Bazos


Add only event.stopPropagation(); on the child ng-click. it will prevent to from the parent ng-click Example:

<div ng-click="parent($event)">
  <div ng-click="child($event); event.stopPropagation()">
  </div>
</div>
like image 42
Tabish Avatar answered Oct 22 '22 04:10

Tabish