Mike Mike - 1 month ago 15x
AngularJS Question

Unable to sort ng-options into alphabetical order


<select ng-model="selectLocation" ng-options="key for key in careerlist.location | orderBy: 'key'">

js (in careerlist controller)

location = ["US-CA-San Clemente", "US- UT- Draper", "US-TX-Dallas", "US-LA-New Orleans", "US-WI-Oshkosh", "US-SC-Charleston", "US-UT-Provo", "US-TX-Fort Worth"]

The select option is populated and functions as intended when making a choice, but it doesn't sort it by alphabetical order.


This seems to be a duplicate of this question. Never the less, if you don't want to read that link, can you tell me if this work?

  ng-options="key for key in careerlist.location | orderBy:'toString()' "

Using toStrig works because you are just using a list of strings.