Duke
Duke

Reputation: 175

ng-repeat display range

I want to display ranges like 3 4 5 6 or 6 7 8 9

How can I do this?

<div ng-app ng-controller="MainCtrl">
    <ul>
        <li ng-repeat="num in nums">{{num}}</li>
    </ul>
</div>

Here is my code:

http://jsfiddle.net/duketopmost/n9brs8hh/

Thanks a lot.

Upvotes: 0

Views: 1040

Answers (1)

Shehryar Abbasi
Shehryar Abbasi

Reputation: 378

How about using limitTo?
docs (angularjs v1.3.15) : https://code.angularjs.org/1.3.15/docs/api/ng/filter/limitTo

<li ng-repeat="num in nums | limitTo: 6 | limitTo: -4">{{num}}</li>

num = 3, 4, 5, 6

<li ng-repeat="num in nums | limitTo: 9 | limitTo: -4">{{num}}</li>

num = 6, 7, 8, 9

jsfiddle: http://jsfiddle.net/n9brs8hh/1/


EDIT: another option would be to create a .filter for more complex operations perhaps.

Upvotes: 2

Related Questions