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

1

4 Answers 4

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>

Sign up to request clarification or add additional context in comments.

2 Comments

Nice to know this .
Thanks "Gaurav Srivastava", Your answer very useful to me and also will helpful to our angular user colleagues.
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>

2 Comments

can it possible without making an array ?
any other way without ng-repeat like for loop an so on?
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

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.