I have an array like this:
$scope.telcodes = ['44', '01', '221', '335'];
How do I use orderBy on a simple array like this to produce an ordered list starting from 01?
I know how to do this on an array containing objects but not on simple arrays like the above.
<li data-ng-repeat="telcode in telcodes | orderBy:????:false track by $index">
You can declare simple proxy
function within your controller and use it:
Controller:
$scope.proxy = function(x) { return x; }
HTML:
<tr ng-repeat="t in telcodes | orderBy: proxy">
However, it gives you string comparison (demo).
To get standard numeric comparison modify proxy
a little (demo):
$scope.proxy = function(x) { return x * 1; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With