Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
881 views
in Technique[技术] by (71.8m points)

angularjs - How to disable parent ng-click?

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"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...