I'm completely new to AngularJS and I am working with an API that returns key-value pairs related to different sports.
$scope.sports = { 1: "Soccer", 2: "Tennis", 3: "Basketball" ... };
My challenge is sorting these items by sport name:
<ul>
<li ng-repeat="(id, value) in sports | orderBy:'value'">
<a ng-href='/page/{{id}}'>{{value}}</a>
</li>
</ul>
Unfortunately, this method doesn't seem to work as expected.
Check out the current output here
Current order:
--------------------
Soccer // id: 1
Tennis // id: 2
Basketball // id: 3
MMA // id: 4
Street dance // id: 5
Aerobics // id: 6
Aerial hoop // id: 7
Desired order:
--------------------
Aerial hoop // id: 7
Aerobics // id: 6
Basketball // id: 3
MMA // id: 4
Soccer // id: 1
Street dance // id: 5
Tennis // id: 2
I attempted sorting within the controller using underscore.js but encountered issues with retaining information about ids. Link to that attempt can be found here: Attempt with Underscore.js
Can anyone provide guidance on how to effectively use `orderBy` in AngularJs when working with (key, value) pairs?