ng options - AngularJS ngOptions sort array -


i have been trying use ng-options display array of fonts in select sorted alphabetically value of items in array.

html

<select ng-options="font font in webfonts | orderby:'font'" name="fonts">      <option value="">choose font</option> </select> 

js

$scope.webfonts = [          'abel', 'crafty girls' , 'lato' , 'average',         'corben', 'quicksand', ... ]; 

i've tried changing value in orderby , other things. i've read through documentation , comments.

what missing? supposed work on objects?

this need do:

<select ng-model="selected" ng-options="font font in webfonts | orderby:'tostring()' " name="fonts"> 
  1. you need add ng-model correctly make binding works list of strings.
  2. you can use tostring() sort if input contains list of strings. since expression of orderby can getter function. result of function sorted using <, =, > operator.

demo


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -