javascript - AngularJS ng-repeat 上的系列

标签 javascript angularjs

我有以下ng-repeat

<div ng-repeat="product in ProductList" ng-show="ProductList.length >=1">
<h3> Product {{ProductList.length + 1}}</h3>

我需要做的就是在 h3 中显示序列号,例如

Product 1
Product 2
....

我该怎么做?

最佳答案

您可以使用$index,参见doc

<div ng-repeat="product in ProductList">
    <h3>Product {{$index + 1}}</h3>
</div>

您不需要 ngShow 因为 ngRepeat 不会迭代空数组

关于javascript - AngularJS ng-repeat 上的系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33193543/

相关文章:

javascript - 没有固定高度的 iOS div 动量滚动(通过 ajax 加载的内容)?

php - 如何在无法从浏览器轻松保存图像的情况下提供图像?

javascript - Lodash 按字母表分组

javascript - 无法访问 jQuery 插件中的原型(prototype)函数

angularjs选择需要不工作的ng-options

javascript - AngularJs $http.post() 发送数据空状态:-1

javascript - 在 React 中处理多个导入的有效方法

html - 跨度不随 child 的大小而增长

javascript - ng-repeat 不迭代范围内的项目

javascript - 使用 ng-view 时 AngularJS 数组不更新