ng-repeat显示html中数组中对象的索引

时间:2015-09-08 03:17:28

标签: javascript html angularjs angularjs-ng-repeat

我想要这个数组:

// Departments is your data source
//Find the department
var department= Departments.FirstOrDefault(d=>d.DepartmentID=="D2");
if(department!=null)
{
  //Get all the orders from that Store
  var orders= department.Store.Departments.SelectMany(d=>d.Orders); 
}

我希望使用angular:

在html中显示数据和索引
var data = [1, 2, 3, 4, 5];

,输出为

<div ng-repeat="data in data">
  <p> index of {{ data }}: {{ something here }} </p>
</div>

可能的?

1 个答案:

答案 0 :(得分:4)

使用$index

  

重复元素的迭代器偏移量(0..length-1)

<div ng-repeat="data in data">
    <p> index of {{ data }}: {{ $index }} </p>
</div>