How to disable parent ng-click?

前端 未结 2 1545
心在旅途
心在旅途 2020-12-17 14:49

I have HTML structure with ng-click:

H

相关标签:
2条回答
  • 2020-12-17 15:10

    Use the stopPropagation method on the angular $event object:

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

    Or pass the $event object as an argument of the ng-click method, and call stopPropagation in the method:

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

    In d:

    $scope.d = function (event) {
        // ...
        event.stopPropagation();
    }
    
    0 讨论(0)
  • 2020-12-17 15:22

    Add only event.stopPropagation(); on the child ng-click. it will prevent to from the parent ng-click Example:

    <div ng-click="parent($event)">
      <div ng-click="child($event); event.stopPropagation()">
      </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题