自动序列号在NG-重复(角)

自动序列号在NG-重复(角)

问题描述:

我使用的NG-重复填写表格与控制器的数据(或服务)。不过,我需要在第一列自动fullfill序列号。目前,我只得到所有列的静态数据为1。

I am using ng-Repeat to fill the table with data in Controller (or from Services). However, I need to fullfill Serial Nos in first column automatically. Currently I am getting only static data as 1 in all 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:

在这里输入的形象描述

我希望在第一列的数字为1,2,3,等我如何与ngRepeat做到这一点?

I want the Numbers in first column to be 1, 2, 3, etc. How can I achieve this with ngRepeat ?

使用 $指数

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