Itsik Mauyhas
Itsik Mauyhas

Reputation: 3984

Angular - Set textarea rows base on the number of rows

I am trying to set textarea rows property to the numer of rows in the text. Here is the textarea:

<textarea rows = "countRowsInText(response.simLog)" cols = "200" style = "overflow:hidden">{{response.simLog}}</textarea>

Ant the countRowsInText() function:

$scope.countRowsInText = function(text){
  var numerOfRowsInText = text.split(\/r\n|\r|\n).length; //rows number - 500
  console.log(numerOfRowsInText); //row number
  return numerOfRowsInText;
}

And it doesn't work, shows only 2 rows. Thanks.

Upvotes: 0

Views: 9029

Answers (2)

Krisalay
Krisalay

Reputation: 235

in your controller u can use:

 var txtArea = document.getElementById('ptest').value.split('\n');    
    $scope.lines = txtArea.length;

then you can use lines in text-area

<textarea rows = "{{lines}}" cols = "200" style = "overflow:hidden">{{response.simLog}}</textarea>

Upvotes: 1

Dina
Dina

Reputation: 1015

Firs guess, {{}} is missed and it should be:

<textarea rows = "{{countRowsInText(response.simLog)}}" cols = "200" style = "overflow:hidden">{{response.simLog}}</textarea>

Upvotes: 4

Related Questions