javascript - Automatic Serial Nos in ng-Repeat (Angular) -


i using ng-repeat fill table data in controller (or services). however, need fullfill serial nos in first column automatically. getting static data 1 in columns.

html:

<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> </head> <body ng-app="myapp" ng-controller="myctrl"> <table> <tr><th>s.no.</th><th>name</th></tr> <tr ng-repeat="x in people"><td>1</td><td>{{x.name}}</td></tr> </table> <script> var app = angular.module('myapp',[]); app.controller('myctrl',function($scope){     $scope.people = [     {name:"peter"},     {name:"lina"},     {name:"roger"}     ]; }); </script> </body>  </html> 

output:

enter image description here

i want numbers in first column 1, 2, 3, etc. how can achieve ngrepeat ?

use $index:

<td>{{$index + 1}}</td> <td>{{x.name}}</td> 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -