最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular - Set textarea rows base on the number of rows - Stack Overflow

programmeradmin9浏览0评论

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.

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.

Share Improve this question edited Aug 21, 2016 at 8:46 Itsik Mauyhas asked Aug 21, 2016 at 8:29 Itsik MauyhasItsik Mauyhas 4,00415 gold badges74 silver badges119 bronze badges 2
  • it looks like your function receives a text argument and it's not being passed – AranS Commented Aug 21, 2016 at 8:41
  • editing it, but I think it will not work. – Itsik Mauyhas Commented Aug 21, 2016 at 8:45
Add a ment  | 

2 Answers 2

Reset to default 4

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

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

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>
发布评论

评论列表(0)

  1. 暂无评论