AngularJS, order text selection with a non-array model? -


this question has answer here:

i using ng-options="ref display (ref, display) in syntax display non-array object dropdown, having trouble ordering dropdown values.

how should use orderby filter sort dropdown display value?

    <div ng-controller="myctrl">       <select name="category" type="text" ng-model="categories " ng-options="ref display  (ref, display) in categories | orderby:'display'" >      </div>      var myapp = angular.module('myapp',[]);     function myctrl($scope) {       $scope.categories = {           cat2: "category 2",           default: "anone",           zone: "zone",         };     } 

http://jsfiddle.net/adukg/13412/

orderby can't applied plain object, alternatively can define method in controller convert object array

demo

var myapp = angular.module('myapp',[]);  myapp.controller('myctrl', function($scope) {    $scope.categories = {        cat2: "category 2",  			default: "anone",  			zone: "zone",  	};         $scope.templatesary = function() {        var ary = [];        angular.foreach($scope.categories, function(val, key)        {                 ary.push({            "category": val                    });        });        return ary;      };  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div ng-app="myapp" ng-controller="myctrl">     <select class="form-control" id="selection" ng-model="currentselected" ng-options="selection.category selection.category selection in templatesary()  | orderby:'category'"></select>  </div>


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -