0

Which selector is faster in an angular 1.x application? I have Jquery included and have been using both in my application as in below:

var paneWidth = angular.element('.side-nav').width(); var paneWidth = jquery('.side-nav').width(); 
2
  • Possible duplicate of stackoverflow.com/questions/17230242/… Commented Aug 16, 2017 at 6:48
  • The biggest difference is that angular.element is a jQuery alias, and returns a jQuery (or jQuery lite) object. Commented Aug 16, 2017 at 6:54

2 Answers 2

0

If jQuery is available, angular.element is an alias for the jQuery function. If jQuery is not available, angular.element delegates to AngularJS's built-in subset of jQuery, called "jQuery lite" or jqLite.

docs

Sign up to request clarification or add additional context in comments.

2 Comments

Ok got it about aliases.Nevertheless , can i conclude that there would be no impact in speed, irrespective of the selectors being used ?
Direct call of the jQuery should be a little faster
0
var paneWidth = jquery('.side-nav').width(); 

From the above code if you didn't include jquery in your angularjs code it doesn't works it through angular errors. To use jQuery, simply ensure it is loaded before the angular.js file.

var paneWidth = angular.element('.side-nav').width(); 

From the above code, angular.element delegates to AngularJS's built-in subset of jQuery, called "jQuery lite" or jqLite. Its already pre build in the angularjs code

Which is Faster?

Sure, jQuery is faster than angular.element().

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.