【问题标题】:Angularjs ng-repeat indexAngularjs ng-repeat 索引
【发布时间】:2014-06-11 10:57:13
【问题描述】:

有没有办法获得 ng-repeat 当前记录索引?我试图给每个记录 div 一个等于记录索引示例的 id:

 <div id="1"> 
 <div id="2"> 
 <div id="3"> 

任何例子都受到高度赞赏。

我使用的 ng-repeat 如下:

      <div ng-repeat="rows in clients.Result">

【问题讨论】:

标签: angularjs


【解决方案1】:

$index 包含当前索引。所以你可以在你的ng-repeat 中使用它,比如{{$index}}

所有这些变量都记录在ng-repeat documentation 的最顶部。

【讨论】:

    【解决方案2】:

    在评估卷曲中使用 $index:

    <div id="{{$index}}" ng-repeat="rows in clients.Result">
    

    PLNKR

    【讨论】:

    • @mchan 确保您了解索引从 0 开始,因此如果您想要 123 喜欢您的演示,那么您可以只使用 id="{{ $index + 1 }}"。另请注意,在转发器上运行过滤器将更改索引以反映可见列表。
    • 您的示例看起来不错,只是为 OP 添加了一些旁注。我已经给你 +1 了 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 2019-06-18
    • 1970-01-01
    • 2017-12-22
    相关资源
    最近更新 更多