Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I'm looking for an option to give start and end while looping the array of object in angular.

Now i'm using ng-repeat.

My use case is like i have a section "top" were 3 items to be shown from "lists"(array of objects) sorted by date

and in another section "more" rest of the items have to be shown that is 4 to lists.length.

and i want to use same "lists" as sources rather than pushing to two different array.

As there is an option to delete items from both sections, deleting item from "top" section should pull items from "more" section to "top".

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Use angular's limitTo filter in your ng-repeat.

ng-repeat="item in items|limitTo:3"

Here is a startWith filter to help also:

app.filter('startWith', [function() {
    return function(input, index) {
        return input.slice(parseInt(index, 10));
    };
}]);

Use it like this:

ng-repeat="item in items|startWith:4"
share|improve this answer
    
Thanks it works like a charm, i added input.length in filter and used 3 instead of 4 – tomalex Apr 8 '14 at 18:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.