3

There is the following code:

<div class="first" ng-click="funcFirst()">
  ... Some other content
  <div class="second" ng-click="funcSecond()">
  </div>
  ... Some other content
</div>

I want to do the following thing: if I click by anything inside "first" div except "second" - execute funcFirst function; if I click by "second" div - execute funcSecond function. Now if I click by "second" I execute funcFirst. How can I do it? I can't change HTML structure. Thanks in advance.

3

1 Answer 1

5

I have solution for it:

script example:

 <script>
    myWebApp = angular.module('myWebApp', []);
    myWebApp.controller("Controller01", function ($scope) {

        $scope.funcFirst = function () {
            alert("click on div 1 content");
        };

        $scope.funcSecond = function () {
            alert("click on div 2 content");
        };
    });

</script>

HTML

<body ng-app="myWebApp">
<div ng-controller="Controller01">

    <div class="first" ng-click="funcFirst()">
        ... click on div 1 content
        <div class="second" ng-click="funcSecond(); $event.stopPropagation();">
            click on div 2 content
        </div>
        ... click on div 1 content
    </div>
</div>

Edit on plunker

Sign up to request clarification or add additional context in comments.

1 Comment

Yes it works fine. This is more a javascript issue that an angular one. You can read this article to learn more about stopPropagation : developer.mozilla.org/fr/docs/Web/API/Event/stopPropagation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.