如何获取数组 ng-repeat 的最后一个索引

Ade*_*han 0 angularjs angularjs-scope

如何使用 ng-repeat 指令获取数组最后一个索引 + 1 ?动态 Profile.addresses[2].site_name

<tr ng-repeat="lines in array">
  <td>
    <input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].site_name ' name='site_name'>
  </td>
  <td>
    <input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].street_address ' name='street_address'>
  </td>
  <td>
    <input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].city ' name='city'>
  </td>
  <td>
    <input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].state ' name='state'>
  </td>
  <td>
    <input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].country ' name='country'>
  </td>
  <td>
    <input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].zip_code ' name='zip_code'>
  </td>
  <td>
    <input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].phone_number ' name='phone_number'>
  </td>

</tr>
Run Code Online (Sandbox Code Playgroud)

rrd*_*rrd 6

您将寻找$last

ngRepeat文档中有许多特殊属性,例如 $index、$first 和 $last 就是其中之一。

  • 你在戏弄我们吗?最后一个索引 + 1 不存在并且超出了数组范围!如果你说你只想要最后一个索引的数字+1,你可以自己加1。 (3认同)