Raghav
Raghav

Reputation: 1064

What is meant by AngularJS element?

I am trying to learn AngularJS. I was reading the https://github.com/angular/angular.js/wiki/Understanding-Directives : "You do NOT have to wrap AngularJS elements in jQuery()"

What is meant by an AngularJS element? In Jquery, if I have a DOM element, say by using document.getElementByID() and if I want to make it a jquery element with access to all of its awesome functions, I will simply say

 var domElement = document.getElementByID("elemID");
 var $domElement = $(domElement); (To cache the element)

So, if in angular I dont have to wrap the DOM element as in Jquery, then can I simply query the DOM and access it and still be able to access all the angular methods. If so, how it is done? Is it because of the ng-app binding? Are all DOM elements inside ng-app internally accessed by Angular and turned to equivalent AngularJS elements?

Upvotes: 1

Views: 737

Answers (1)

JB Nizet
JB Nizet

Reputation: 691765

The wiki page is talking about the elements passed by Angular as arguments to the compile and link functions of the directive:

link: function LinkingFunction($scope, $element, $attributes) { ... }
                                       ^-- here

If you get an element from the DOM using document.getElementById(), it won't be wrapped in jQuery automatically.

Upvotes: 2

Related Questions