Angular 点击停止传播事件

Angular On click stop propagation event

如何在 jQuery 代码中调用 Angular 函数?我试过 f

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

但我收到以下错误:

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

那么,我如何知道我的控制器绑定了哪个 ID?我是 AJS 的新手,这是我正在修改的现有 AJS 应用程序。所以我不确定控制器是如何动态注入的?

以angular方式进行:

在模板中使用 ng-click 而不是使用 jQuery click 事件。

第二件事:您不需要将 jQuery 包装在 angular DOM 选择器中,因为 angular.element 与 jQuery 完全相同$(".someClass")

在你的例子中 scope() 是什么意思?

问题不在于 e.stopPropagation(); 它在 angular 选择器中。

angular.element($(".someClass")) // << This is wrong

应该是

angular.element(".someClass")

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;
}