Episodes

by Kunal Paul

HTML

<body ng-app="myApp">
  <div ng-controller="myCtrl">
   <select class="form-control" name="cruiseCategoryId" id="cruiseCategoryId" ng-model="countries" ng-options="country as country.countryName for country in getSortedCountryList()">
  </select> Selected {{countries}}
  </div>
  
</body>

JavaScript

var app = angular.module('myApp', []);
app.controller('myCtrl',function($scope,$window){
$scope.name = 'World';
$scope.ctrl = { //---->Source
			countriesList : {
      	'DK': {countryName: 'Denmark', preferredLanguage: 'DA'},
    		'US': {countryName: 'USA', preferredLanguage: 'EN'},
        'BEL':{countryName: 'Belgium', preferredLanguage: 'NL'}
      }
}


$scope.getSortedCountryList = function(){
$scope.sorted = {};
Object.keys($scope.ctrl.countriesList)
								.sort(function(a,b){
                	if($scope.ctrl.countriesList[a].countryName < $scope.ctrl.countriesList[b].countryName) return -1;
      						if($scope.ctrl.countriesList[a].countryName > $scope.ctrl.countriesList[b].countryName) return 1;
      						return 0;
                })
                .forEach(function(v, i) {
                	$scope.sorted[v] = $scope.ctrl.countriesList[v];
       					});
return $scope.sorted;
}
});