Do ng-click, ng-mouseover etc. Create observers and slow down the page? Is this better than jQuery event binding?

I was wondering if directives like ng-click, ng-mouseover, etc., when used in large numbers throughout the application, would lead to performance problems similar to ng-repeat?

I am developing an application using AngularJS. I am already loaded with problems due to ng-repeat and the number of watchers it creates. The effect has been affected, and I'm working on it.

+4
source share
1 answer

No extra hours created as part of angular event directives.

jquery ( jqLite, jquery ), (.. ng-click). , angular. , .

var ngEventDirectives = {};
forEach(
  'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit focus blur copy cut paste'.split(' '),
  function(name) {
    var directiveName = directiveNormalize('ng-' + name);
    ngEventDirectives[directiveName] = ['$parse', function($parse) {
      return {
        compile: function($element, attr) {
          var fn = $parse(attr[directiveName]);
          return function(scope, element, attr) {
            element.on(lowercase(name), function(event) {
              scope.$apply(function() {
                fn(scope, {$event:event});
              });
            });
          };
        }
      };
    }];
  }
);

, $scope.apply() , angular, .

+10

Source: https://habr.com/ru/post/1534682/


All Articles