Nick Cooper
Nick Cooper

Reputation: 750

Angular JS hide first element of ng-repeat

How would I hide the first element of an ng-repeat?

<div ng-repeat="item in items" ng-hide="true">
    <div>{{ item.value }}</div>
</div>

This works in that the whole ng-repeat block is hidden, but how would I hide only the first item in items? I want to display it completely differently using more prominent html/etc, so it's useful to have it in that list of data.

Upvotes: 55

Views: 37098

Answers (4)

KKProg
KKProg

Reputation: 11

In case you need to skip last, use ng-if='!$last'.

Upvotes: 0

Rebecca
Rebecca

Reputation: 1062

There's a simpler solution in more recent versions of Angular.

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="item in items | limitTo: items.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 items array's length (which is less than items.length, but limitTo will handle that just fine).

Upvotes: 1

Oleg
Oleg

Reputation: 619

No need to hide, just use a filter to exclude the first item from the list:

<div ng-repeat="item in items|filter:$index>0">
    <div>{{ item.value }}</div>
</div>

Upvotes: 8

Xesued
Xesued

Reputation: 4167

You can do this

<div ng-repeat="item in items" ng-show="!$first">
    <div>{{ item.value }}</div>
</div>

Here are the docs: http://docs.angularjs.org/api/ng.directive:ngRepeat

Upvotes: 114

Related Questions