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"> - you need add ng-model correctly make binding works list of strings.
- you can use
tostring()sort if input contains list of strings. since expression oforderbycan getter function. result of function sorted using <, =, > operator.
Comments
Post a Comment