Payal Dobaria
Payal Dobaria

Reputation: 39

Find element without using angular.element and jQuery

I have an Angular controller which uses pure Angular (no jQuery or Javascript). My problem is that I need to find and element without using jQuery or Javascript. I searched a lot on net but could not find any helpful answer.

The solution I found was to use angular.element, but it is not a good idea to use it.

Can anybody help me how to find element without using jquery.element or angular.element?

Thanks in advance.

Upvotes: 1

Views: 346

Answers (2)

aprok
aprok

Reputation: 1157

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

From here

PS: if you still want to use something other than this look here

Oh, one other edit: you can't actually use angular without javascript, since it is javascript framework..

Upvotes: 2

terpinmd
terpinmd

Reputation: 1028

I would recommend is to create a directive. The element is handed to you in the linking function:

link: function(scope, elem, attr) {
    //elem is the dom element that contains the directive...your target object
}

If you do it like this you dont have to create a selector that would look at the entire dom from your controller. In your directive you could also do document.querySelector(".myclass") if the elem object doesn't work for your use case for whatever reason....but I think it should.

Upvotes: 1

Related Questions