1

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.

2
  • why isn't it a good idea to use angular.element ? Commented Jun 16, 2016 at 12:55
  • 1
    Accessing the dom in angular controllers is frowned upon. Create a directive which hands you the exact element you need in the link function. Commented Jun 16, 2016 at 12:56

2 Answers 2

2

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..

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.