Option Select object grouped by property
Description
The following code shows how to option Select object grouped by 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', []);
<!-- ww w . j a v a 2 s . com-->
app.controller('MainCtrl', function($scope) {
$scope.users = [
{ firstName: 'J', lastName: 'J', email: 'j@example.com', sex:"Female"},
{ firstName: 'A', lastName: 'A', email: 'a@example.com', sex:"Female"},
{ firstName: 'S', lastName: 'S', email: 's@example.com', sex:"Male"},
{ firstName: 'K', lastName: 'K', email: 'k@example.com', sex:"Male"}
];
$scope.getFullName = function(user) {
return user.firstName + ' ' + user.lastName;
};
});
</script>
</head>
<body ng-controller="MainCtrl">
<select ng-model="chosenUser"
ng-options="getFullName(user) group by user.sex for user in users"></select>
Selected User: {{ chosenUser }}
</body>
</html>