Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
如果你的回调决定传播是否应该停止,我发现将$event对象传递给回调是有用的。
<div ng-click="parentHandler($event)">
<div ng-click="childHandler($event)">
</div>
</div>
然后在回调本身中,您可以决定是否停止事件的传播:
$scope.childHandler = function ($event) {
if (wanna_stop_it()) {
$event.stopPropagation();
}
...
};
ngClick指令(以及所有其他事件指令)创建$event在相同范围内可用的变量。这个变量是对JS event对象的引用,可以用来调用stopPropagation():
<table>
<tr ng-repeat="user in users" ng-click="showUser(user)">
<td>{{user.firstname}}</td>
<td>{{user.lastname}}</td>
<td>
<button class="btn" ng-click="deleteUser(user.id, $index); $event.stopPropagation();">
Delete
</button>
</td>
</tr>
</table>