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.
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.
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.
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.
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;
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With