ng-Repeat 中的自动序列号(角度) [英] Automatic Serial Nos in ng-Repeat (Angular)
本文介绍了ng-Repeat 中的自动序列号(角度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 ng-Repeat 用控制器(或来自服务)中的数据填充表.但是,我需要自动填写第一列中的序列号.目前,我在所有列中只获取静态数据为 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>
输出:
我希望第一列中的数字为 1、2、3 等.如何使用 ngRepeat 实现此目的?
I want the Numbers in first column to be 1, 2, 3, etc. How can I achieve this with ngRepeat ?
推荐答案
使用$index
:
<td>{{$index + 1}}</td>
<td>{{x.name}}</td>
这篇关于ng-Repeat 中的自动序列号(角度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文