Can angularjs ng-click process events during the capturing phase?

£可爱£侵袭症+ 提交于 2019-11-29 01:28:01

Lets see the source code of ng-click at ngEventDirs.js#L50

As you can see the ng-click and all other event directives using .on().

So, the answer is No, it is not possible.

If you really need it, you could write a custom directive for that. For example, modify the code of ng-click a bit:

.directive('captureClick', function($parse) {
  return {
    restrict: 'A',
    compile: function(element, attrs) {
      var fn = $parse(attrs.captureClick);
      return function(scope, element) {
        element[0].addEventListener('click', function(event) {
          scope.$apply(function() {
            fn(scope, {
              $event: event
            });
          });
        }, true);
      };
    }
  }
});

and use it like this:

<div title="A" ng-click="onBubbled($event)" capture-click="onCaptured($event)">
  <div title="B" ng-click="onBubbled($event)" capture-click="onCaptured($event)">
    <div title="C" ng-click="onBubbled($event)" capture-click="onCaptured($event)">
      Yo!
    </div>
  </div>
</div>

Example Plunker: http://plnkr.co/edit/SVPv0fCNRQX4JXHeL47X?p=preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!