我的代码:
<div ng-click="someAction()">
<button ng-click="otherAction()"></button>
</div>
单击按钮应该只调用otherAction()而不调用someAction()。单击div的其余部分应调用someAction()。
答案 0 :(得分:4)
您可以使用$event.stopPropagation()
来阻止从内部范围到外部范围的传播:
<div ng-click="someAction()">
<button ng-click="otherAction(); $event.stopPropagation();"></button>
</div>
或
<div ng-click="someAction()">
<button ng-click="otherAction($event)"></button>
</div>
修改otherAction
代码如下:
$scope.otherAction = function($event) {
$event.stopPropagation();
// Existing code
}
答案 1 :(得分:0)
按钮按钮点击
传递事件<button ng-click="otherAction($event)"></button>
和onAction函数你只需要停止或防止默认
$scope.otherAction = function($event){ $event.stopPropagation; };