我正在使用 ng-Repeat 将 Controller (或来自服务)中的数据填充到表格中。但是,我需要自动在第一列中填写序列号。目前我在所有列中只获得静态数据 1。
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>
输出:
我希望第一列中的数字为 1、2、3 等。如何使用 ngRepeat 实现此目的?
最佳答案
使用$index
:
<td>{{$index + 1}}</td>
<td>{{x.name}}</td>
关于javascript - ng-Repeat( Angular )中的自动序列号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35057333/