theintellects theintellects - 6 months ago 24
AngularJS Question

Offset index by 1 in ng-options

I have a selection dropdown populated by an object like this:

<select class="form-control" ng-model="nonexistantmodel" ng-options="idx as idx+1 + order for (idx, order) in amazon.orders">


I'm trying to get the array indices to show up starting from 1. (0,1,2,3 become 1,2,3,4)

But of course
idx+1
only ends up joining the string and it ends up like
01, 11, 21, 31


I've also tried applying the
number
filter but to no avail:

(idx+1 | number: 0)
or
(idx | number: 0) + 1
or
(idx | number: 0) + (1 | number: 0)


but they all seem to just join strings with the same result.

Is there any way to accomplish this?

Answer

Simply change idx+1 with idx*1+1 or idx/1+1 or idx-0+1.

See a live example.