AngularJS: ng-repeat from second index

懵懂的女人 提交于 2019-12-23 09:21:06

问题


I would like to ng-repeat but only from the second array element until the last. I tried to use

ng-repeat="entry in entries | filter: $index==0"

but this one didn't work. If I attempt to use ng-if, like this

ng-repeat="entry in entries" ng-if="$index != 0"

I am getting error in transclusion.

What's the best solution for this? BTW, my AngularJS version is 1.1.5 because my app is a plugin for Hawtio (which is still stuck in version 1.1.5). Thanks.


回答1:


Why not just:

ng-repeat="entry in entries.slice(1,entries.length)"

Fiddle: http://jsfiddle.net/10d6o1aq/




回答2:


You can try this:

ng-repeat="entry in entries" ng-show="!$first"

Here's the reference.




回答3:


hide first element using $first

<div ng-repeat="entry in entries" ng-hide="$first">
  ...
</div>



回答4:


There's a simpler solution in more recent versions of Angular (which won't work for the original question, given their restriction on Angular version 1.1.5, but it will work for others coming across this post)

The filter "limitTo" now supports a "begin" argument (docs):

{{ limitTo_expression | limitTo : limit : begin}}

So you can use it like this in a ng-repeat:

ng-repeat="entry in entries | limitTo: entries.length : 1"

This means that ng-repeat will begin at index 1 (instead of the default index 0) and will continue for the rest of the entries array's length (which is less than entries.length, but limitTo will handle that just fine).



来源:https://stackoverflow.com/questions/26624341/angularjs-ng-repeat-from-second-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!