5

I want to bind html table row by specific count times using angularJS binding like below:

<table>
    <tr ng-repeat="x in 5">
       <td>abc</td>
    </tr>
</table>

If anybody have solution, please reply as possible. Thanks

nativegrip
  • 892
  • 10
  • 20
  • 5
    Possible duplicate of [Way to ng-repeat defined number of times instead of repeating over array?](https://stackoverflow.com/questions/16824853/way-to-ng-repeat-defined-number-of-times-instead-of-repeating-over-array) – Wasif Khan Jul 25 '17 at 09:30

4 Answers4

8

You can use constructor like this (no code in js required) :

var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope) {

});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body>

  <div ng-app="myApp" ng-controller="myCtrl">
    <table>
      <tr ng-repeat="n in [].constructor(10)  track by $index">
        <td>abc</td>
      </tr>
    </table>
  </div>

</body>

</html>
Gaurav Srivastava
  • 3,232
  • 3
  • 16
  • 36
4

Pass the number to a function and generate the array according to it.

DEMO

var app = angular.module('myapp',[]);
app.controller('ctrl',function($scope){
     $scope.getNumber = function(num) {
        return new Array(num);   
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp">
    <div ng-controller="ctrl">
      <table>
       <tr ng-repeat="x in getNumber(5) track by $index">
        <td>abc</td>
       </tr>
      </table>        
    </div>
</div>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0

The following code will work for you:

Number of visible Values: {{(data|filter:query).length}}

Total number of Values: {{data.length}} summary

{{data.length}} - prints total number of Values

{{(data|filter:query).length}} - prints filtered number of Values

Deepak
  • 571
  • 7
  • 19
0

Sol 1

<table>
    <tr ng-repeat="x in [1,2,3,4,5]">
       <td>abc</td>
    </tr>
</table>

Sol 2

or create blank array in back end and use here like in laravel

$scope.newarr = new Array(5);

IN angular

<table>
    <tr ng-repeat="x in newarr track by $index">
       <td>abc</td>
    </tr>
</table>
jack
  • 589
  • 8
  • 22