我有ng-click
的HTML结构:
<div ng-click="parent()">
<div ng-click="d"></div>
</div>
如果我执行ng-click="parent()"
ng-click="d"
答案 0 :(得分:29)
在角度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();
}
答案 1 :(得分:2)
仅添加event.stopPropagation();在孩子的ng点击。它将阻止来自父ng-click 例如:
<div ng-click="parent($event)">
<div ng-click="child($event); event.stopPropagation()">
</div>
</div>