Search code examples
angularjssortingangularjs-limitto

LimitTo and sortBy not working


I have 2 questions in 1 post: I would like to limit the number of result with 10 results and I would like to sort post by date but it's not working because it sort by user then by date and I would like to sort by date no matter the user.

Here what i tried:

<ul ng-repeat="item in customarray  | orderBy:'-tickets[0].date' | limitTo : 10 track by $index">
    <div  ng-repeat="new in item.tickets   track by $index ">
        <li class="row"><div class="col-md-2 date text-center">{{new.date | date}}</div><div class="col-md-3 date text-center"> {{item.username}}</div> <div class="col-md-5 date text-center">{{new.titre}}</div> <div class="col-md-2 date text-center">{{new.status}}</div></li>
    </div>
</ul>

The problem is that my data is contain in 2 ng-repeat.


Solution

  • I think it should be

    ng-repeat="item in customarray track by $index | orderBy:'-tickets[0].date' | limitTo : 10"

    or

    ng-repeat="item in customarray | orderBy:'-tickets[0].date' | limitTo : 10"

    No need to add track by $index because it will automatically track by $index