1

I have a textarea, which should be resized to the scrollHeight when it is loaded. I have no problem with key events to resize the textarea like this:

$scope.resize= function (event) {
                        //Auto size:
     var element = typeof event === 'object' ? event.target : document.getElementById(event);
     var scrollHeight = element.scrollHeight - 60; 
     element.style.height = scrollHeight + "px";
}

But I can not resize it, when the element is loaded. I tried with $element and $element[0], but I noticed that the height of $element is 0. And I don't want to fit the height by window height (I can get window height by $window). Is there any way to get the element.height and element.scrollHeight after loading the element in angular?

3

1 Answer 1

1

Toss it behind a $timeout as that will allow angular to digest and the element should be created.

$timeout(function(){
    //do work on element here
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.