自动序列号在NG-重复(角) [英] Automatic Serial Nos in ng-Repeat (Angular)

查看:156
本文介绍了自动序列号在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>

这篇关于自动序列号在NG-重复(角)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆