Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS how to get the element scrollHeight value?

Tags:

angularjs

I am writing angularJS directive, in this directive I want to get the select list box scrollHeight value in angularJS, but it is undefined.

How can I get this value please? I can get this value in jquery.

like image 452
jamie2015 Avatar asked Mar 30 '15 09:03

jamie2015


People also ask

How do you get scrollHeight?

To get the height of the scroll bar the offsetHeight of div is subtracted from the clientHeight of div. OffsetHeight = Height of an element + Scrollbar Height. ClientHeight = Height of an element. Height of scrollbar = offsetHeight – clientHeight.

What is scrollHeight?

Definition and Usage The scrollHeight property returns the height of an element including padding, but excluding borders, scrollbars, or margins. The scrollHeight property returns the height in pixels. The scrollHeight property is read-only.

How do I change the scroll height in jQuery?

One need to use scrollHeight property to get height of the scroll view of an element. If you are using jQuery 1.7 or higher version then use prop(), otherwise use attr(). In the code sample, I have used "prop()" to get value of "scrollHeight" property.


1 Answers

Inside your directive link function:

app.directive("scrollHeightDetector", function() {
     return {
       restrict : "AEC",
       link : function(scope, element, attrs) {
           // here you can use element to get the height

           var height = element[0].scrollHeight;


        }
    }
});
like image 187
mohamedrias Avatar answered Nov 15 '22 00:11

mohamedrias