Sorting dropdown alphabetically in AngularJS

The Solution to Sorting dropdown alphabetically in AngularJS is


Angular has an orderBy filter that can be used like this:

<select ng-model="selected" ng-options="f.name for f in friends | orderBy:'name'"></select>

See this fiddle for an example.

It's worth noting that if track by is being used it needs to appear after the orderBy filter, like this:

<select ng-model="selected" ng-options="f.name for f in friends | orderBy:'name' track by f.id"></select>

~ Answered on 2012-09-07 03:02:13


Most Viewed Questions: