3

I am working on creating a AngularJS site that DOES NOT use JQuery. In a directive, the values that are passed are

EngagementApp.directive('movingAside', function() {
    return {
        restrict : 'A',
        link : function(scope, element, attributes) {

      }
    }
});

And html looks like:

<div class="aside" moving-aside>...Content...</div>

Doing things like element.clientHeight returns an undefined.

How can get the attributes(height, width, offset, etc) of the element without using JQuery and only AngularJS functions?

11
  • 3
    When you are using angular you're using jQuery already(angularjs itself uses jQuery lite)... I hope I didn't ruin your mood for the day. Commented Sep 17, 2013 at 14:33
  • If I'm using JQLite, then why doesn't $(element) work? Commented Sep 17, 2013 at 14:38
  • What exactly are you trying to do? bare in mind it's jQuery lite, so some functions are missing or it wasn't lite... Commented Sep 17, 2013 at 14:40
  • Get width, height and offset of the current element. Commented Sep 17, 2013 at 14:41
  • I meant how are you using $(element)? Commented Sep 17, 2013 at 14:41

2 Answers 2

14

Use element[0].clientHeight | offsetHeight | scrollHeight

element[0] gives you access to the first DOM element in the JQLite selector collection while clientHeight is a built in property of the DOM element.

EngagementApp.directive('movingAside', function() {
    return {
        restrict : 'A',
        link : function(scope, element, attributes) {
            console.log(element[0].clientHeight);
      }
    }
});

There are 3 different heights you can get depending on what you're after:

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

Comments

0

Try angular.element(element).css('height')

1 Comment

This doesn't work as it would only read the css height value. Not the actual element's height.

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.