Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable ng-click in parent div [duplicate]

I have next html:

<div class="parent"
         ng-click="ParentClick()">
    .
    .
    .
    <div class="child" ng-click="ChildClick()">
       Some Text
    </div>
</div>

So, when I click on Some Text, I have two method calls: ParentClick(), ChildClick(). Is it possible to disable ParentClick() event when I clicking on Some Text, in CSS way?

like image 828
Ted Avatar asked Mar 08 '23 06:03

Ted


1 Answers

When clicking on the ChildClick() you want to run event.stopPropagation() in order to prevent the click event to bubble up the DOM tree

function ChildClick() {
    event.stopPropagation()
    ....
}

In case you have the ChildClick function part of the $scope you can pass the $event to the function and use it inside:

<div class="child" ng-click="ChildClick($event)">
</div>

$scope.ChildClick = function ($event) {
    $event.stopPropagation();
    ...
};
like image 196
Dekel Avatar answered Mar 16 '23 12:03

Dekel