I try to order a numeric array, but I don't get it. What is wrong?
An example: http://plnkr.co/edit/FheDOnr6ZmTJN0bFpgbB?p=preview
<select data-ng-model="current" data-ng-options="number as number for number in numbers | orderBy:'number'"></select>
I try to order a numeric array, but I don't get it. What is wrong?
An example: http://plnkr.co/edit/FheDOnr6ZmTJN0bFpgbB?p=preview
<select data-ng-model="current" data-ng-options="number as number for number in numbers | orderBy:'number'"></select>
You can use a function to order too:
<select
data-ng-model="current"
data-ng-options="number as number for number in numbers | orderBy:'valueOf()'">
</select>
Should work.
Cause you were saying to order by the property number which doesn't work cause they're just plain integers which doesn't have any property called number but they do have a valueOf method which does the trick.
You could also use just number without quotations (as suggested in a comment) so it will just pass the variable instead of a property.
You could also use just number without quotations (as suggested in a comment) so it will just pass the variable instead of a property. ?orderBy:'number' angular tries to find the property number inside the value. In this case, they're integers so they can't have that property by default. However if you only pass number to orderBy with no quotes, you're passing the variable, that is, the raw integer so orderBy can work out the order.
orderBy:'number'to thisorderBy:number