一尘不染

如何禁用父级ng-click?

angularjs

我有HTML结构ng-click

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

如何禁用外ng-click="parent()",如果我做ng-click="d"


阅读 204

收藏
2020-07-04

共1个答案

一尘不染

stopPropagation在角度$event对象上使用该方法:

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

或将$event对象作为ng-click方法的参数传递,然后调用stopPropagation方法:

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

d

$scope.d = function (event) {
    // ...
    event.stopPropagation();
}
2020-07-04