I was wondering if directives like ng-click, ng-mouseover etc when used in large numbers throughout the application, would result in performance issues similar to that of ng-repeat?
I am developing an application with AngularJS. I am already loaded with problems because of ng-repeat and the number of watchers it creates. The performance has been affected, and I'm working on it.
For a single btn, it's ok to use ng-click or onclick in the ng-app . There is no difference between the two functions. For effective team work, you,d better to have an account with each other. In Angular apps, ng-click is recommended.
The ng-click Directive in AngluarJS is used to apply custom behavior when an element is clicked. It can be used to show/hide some element or it can pop up an alert when the button is clicked. Parameter Value: expression: It specifies when the particular element is clicked then the specific expression will be evaluated.
Definition and Usage The ng-mouseover directive tells AngularJS what to do when a mouse cursor moves over the specific HTML element. The ng-mouseover directive from AngularJS will not override the element's original onmouseover event, both will be executed.
There are no extra watches created as part of angular's event directives.
The event directives are fairly straight forward and use jquery (or jqLite if jquery isn't included) to add the event listener to the element with the directive (i.e. ng-click). Here is the code that sets up the event directives in angular. As you can see they do not create a watch.
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});
});
});
};
}
};
}];
}
);
Keep in mind, a $scope.apply() kicks off a digest loop where the angular async queue is processed and watch list is iterated over.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With