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?

Manuela
  • 1,379
  • 3
  • 16
  • 25
  • Maybe this way of getting elements would help: http://stackoverflow.com/questions/18302493/is-there-a-way-to-get-the-raw-dom-element-from-an-angular-element – changtung Jul 20 '15 at 15:22
  • I believe what your looking for is this http://stackoverflow.com/questions/454202/creating-a-textarea-with-auto-resize – Ernesto Rendon Jul 20 '15 at 15:25
  • I think you should see my answer for angularjs implementation https://stackoverflow.com/questions/454202/creating-a-textarea-with-auto-resize/45947590#45947590 – chrmcpn Nov 28 '17 at 20:46

1 Answers1

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
});
Mathew Berg
  • 28,625
  • 11
  • 69
  • 90