Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get height of element in angularjs

I have DOM element,with id={{child.id}}container

 <div id={{child.id}}container layout="column" flex layout-align="start center" class='container' dragula='"first-bag"' ng-init="vm.getAssociatedWorkItems(child.id); vm.getElementHeight(child.id+'container');">
    <div layout="column" class="md-whiteframe-5dp capitalize itemsInList" ng-repeat="item in vm.items | filter:search" id={{item.id}}child>
        <div class="workItemName">{{vm.getWorkItemName(item.metadata)}}</div>
        <div class="workItemDescription">{{vm.getWorkItemDescription(item.metadata)}}</div>
    </div>
</div>

I want to get height of this element, and according to height deside to list items in ng-repeat or not. How to get DOMs height in angularjs?

like image 262
Serhiy Avatar asked Oct 06 '16 08:10

Serhiy


People also ask

How do you find the height of an element?

In JavaScript, you can use the clientHeight property, which returns an element's height, including its vertical padding. Basically, it returns the actual space used by the displayed content. For example, the following code returns 120, which is equal to the original height plus the vertical padding.


1 Answers

Use angular built-int jqlite with angular.element():

angular.element(".myDiv")[0].offsetHeight;

Beware: don't pollute your controller with DOM manipulation. It's a bad practise and you should do this kind of operations in directives.

Edit 1

OP used this mid way after my suggestion:

var element = angular.element(document.querySelector('#id')); 
var height = element[0].offsetHeight;
like image 189
illeb Avatar answered Oct 20 '22 06:10

illeb