AngularJS: ng-repeat from second index

2019-06-18 04:50发布

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.

4条回答
走好不送
2楼-- · 2019-06-18 05:11

hide first element using $first

<div ng-repeat="entry in entries" ng-hide="$first">
  ...
</div>
查看更多
ら.Afraid
3楼-- · 2019-06-18 05:16

You can try this:

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

Here's the reference.

查看更多
放荡不羁爱自由
4楼-- · 2019-06-18 05:17

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).

查看更多
一纸荒年 Trace。
5楼-- · 2019-06-18 05:25

Why not just:

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

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

查看更多
登录 后发表回答