我有ng-click的HTML结构:
<div ng-click="parent()"> <div ng-click="d"></div> </div>
我如何禁用外部ng-click =“parent()”如果我执行ng-click =“d”
在angular $event对象上使用stopPropagation方法:
<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(); }