How to get body
element in angular directive? my objective is to do what one do with jquery $('body').innerWidth();
inside directive. I do not want to use jquery but angular built-in jqlite implementation.
Javascript – Angularjs – get body element inside directive
angularjsjavascript
Related Topic
- Javascript – What does “use strict” do in JavaScript, and what is the reasoning behind it
- Javascript – event.preventDefault() vs. return false
- Javascript – How to decide when to use Node.js
- Javascript – Scroll to an element with jQuery
- Angularjs – ‘this’ vs $scope in AngularJS controllers
- Angularjs – the difference between ‘@’ and ‘=’ in directive scope in AngularJS
- AngularJS: Service vs provider vs factory
- Javascript – How to access the correct `this` inside a callback
Best Answer
If you need to access the body element from within a directive that is applied on another element, you can make use of the $document service like so..
You could also use the DOM traversal methods provided in jqLite (though they are much less powerful than what jQuery offers). For example, you could do a recursive lookup using the
angular.element.parent()
method to find the body tag.