user1477955
user1477955

Reputation: 1670

AngularJS - Cannot get height of an element

I cannot get the height of an rendered element. It returns null. I need the element to check its height it self without user interaction.

HTML

<span ng-if="contentHeight($element)" ></span>

JS

    $scope.contentHeight = function(element){
        console.log($(element).height());
        return true;
    }; 

Upvotes: 0

Views: 135

Answers (1)

enjoibp3
enjoibp3

Reputation: 79

It might work better for you if you use a directive here because it passes the element into the directive itself.

HTML

<span class="directive"></span>

JS

app.directive('directive', function(){
    return{
        restrict: 'C',
        link: function(scope, element, attrs){
            console.log($(element).height());
        }
    }
});

I'm not sure exactly what you're trying to do, but that might solve your problem :)

Edit: added documentation! https://docs.angularjs.org/guide/directive

Upvotes: 2

Related Questions