问题
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