Ng-Options-6

 

In this example, we have an array named staffMembers with first name,last name and designation. In the first dropdown we bind the first name and last name with the ng-options directive. In the second dropdown we bind the first name and last name with the ng-options directive and group by designation.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="Example"> <div ng-controller="ExampleController" ng-init="StudentId=1"> <div class="container"> Staff: <select ng-model="StaffMember" class="form-control" ng-options=" p.firstName+','+p.lastName for p in staffMembers"></select><br /> Staff Group by: <select ng-model="StaffMember" class="form-control" ng-options=" p.firstName+','+p.lastName group by p.designation for p in staffMembers"></select><br /> <pre>{{StaffMember}}</pre> </div> </div> <script> var app = angular.module("Example", []); app.controller('ExampleController', ['$scope', function ($scope) { $scope.staffMembers = [{ firstName: 'Archie', lastName: 'Smith', designation: 'Developer' }, { firstName: 'Arran', lastName: 'Taylor', designation: 'Developer' }, { firstName: 'Alastair', lastName: 'Cook', designation: 'Designer' }]; }]); </script> </body> </html>
Output