Search code examples
javascriptjqueryangularjsstoppropagation

Angular On click stop propagation event


How Do I make a call to Angular function in my jQuery code? I tried the f

$(document).on('click', '.myBtn', function(e) {
    angular.element($(".someClass")).scope().clearBtnItems();
    e.stopPropagation();
    console.log("stop..prop");
});

But i get following error:

Uncaught TypeError: angular.element(...).scope(...).clearAllResortsOption is not a function

So, how do I know which ID is bound to my controller? I am new to AJS and this is an existing AJS app which I am modifying. So I am not sure, dynamically how the controllers are injected?


Solution

  • write seperate ng-click for both parent and child
    <div ng-click = "sm.clearBtnItems()"><div ng-click ="removeBubbling($event)"></div>
    

     $scope.removeBubbling = function($event){
          // do some code here
          // Prevent bubbling to showItem.
          // On recent browsers, only $event.stopPropagation() is needed
          if ($event.stopPropagation) $event.stopPropagation();
          if ($event.preventDefault) $event.preventDefault();
                $event.cancelBubble = true;
                $event.returnValue = false;
    }