Option Select a property by another property ordered by third property

Description

The following code shows how to do option Select on a property by another property ordered by third property.

Example


<!DOCTYPE html>
<html  ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
  <script>
var app = angular.module('myApp', []);
<!--from ww  w .jav a2  s .  c o  m-->
app.controller('MainCtrl', function($scope) {
  $scope.countriesByCode = {
    'AF' : 'AngularJS',
    'BJ' : 'Beijing',
    'BM' : 'BMW'
  };

  $scope.countriesByName = {
    'AngularJS' : 'AF',
    'Beijing' : 'BJ',
    'BMW' : 'BM'    
  };
    $scope.getFullName = function(user) {
      return user.firstName + ' ' + user.lastName;
    };
});
  
  </script>
</head>
<body ng-controller="MainCtrl">
  
  <select ng-model="chosenCountryCode" ng-options="code as name for (code, name) in countriesByCode"></select>
  Selected Country Code: {{ chosenCountryCode }}
  

</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities