Itsik Mauyhas Itsik Mauyhas - 3 months ago 10
AngularJS Question

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.

Sep Sep
Answer

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

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