Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip first item in ng-repeat

Tags:

angularjs

I want to skip the first item in ng-repeat

..first item here    <ul class="highlight-topright">         <li ng-repeat="item in hpHeadlines | filter:$index>0">           ...         </li> </ul> 

it doesn't work, anything wrong here ?

I understand that i can use ng-if, ng-show to hide things but I just cannot get why the filter doesn't work in 1.3.x in this case.

Thanks.

like image 694
nam vo Avatar asked Dec 25 '14 07:12

nam vo


People also ask

How do I filter in NG-repeat?

The ng-repeat values can be filtered according to the ng-model in AngularJS by using the value of the input field as an expression in a filter. We can set the ng-model directive on an input field to filter ng-repeat values.

Does ng-repeat create a new scope?

Directives that Create Scopes In most cases, directives and scopes interact but do not create new instances of scope. However, some directives, such as ng-controller and ng-repeat, create new child scopes and attach the child scope to the corresponding DOM element.

How do I get the index of an element in NG-repeat?

Note: The $index variable is used to get the Index of the Row created by ng-repeat directive. Each row of the HTML Table consists of a Button which has been assigned ng-click directive. The $index variable is passed as parameter to the GetRowIndex function.

How do you use NG-repeat in a table?

Definition and UsageThe ng-repeat directive repeats a set of HTML, a given number of times. The set of HTML will be repeated once per item in a collection. The collection must be an array or an object. Note: Each instance of the repetition is given its own scope, which consist of the current item.


2 Answers

<ul class="highlight-topright">         <li ng-repeat="item in hpHeadlines" ng-if="$index > 0">           ...         </li> </ul> 
like image 70
dhavalcengg Avatar answered Oct 13 '22 01:10

dhavalcengg


Use $first for this:

<ul class="highlight-topright">         <li ng-repeat="item in hpHeadlines" ng-hide="$first">           ...         </li> </ul> 

Or,

  <ul class="highlight-topright">             <li ng-repeat="item in hpHeadlines" ng-if="!$first">               ...             </li>     </ul> 
like image 42
Ved Avatar answered Oct 13 '22 00:10

Ved