Ng-Options-9

 

Ng-options create list of options using array of objects staffMembers.It will show firstName and lastName if ng-show value is true.

 
 
 
<!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> </head> <body ng-app="Example"> <div ng-controller="ExampleController"> <select ng-model="staffMember"> <option value=''>--Select Name--</option> <option ng-repeat="p in staffMembers">{{p.firstName}}, {{p.lastName}}</option> </select> <pre ng-show="staffMember!='' && staffMember!=null" >Name: {{staffMember}}</pre> </div> <script> var app = angular.module("Example", []); app.controller('ExampleController', ['$scope', function ($scope) { $scope.staffMembers = [{ firstName: 'Archie', lastName: 'Smith' }, { firstName: 'Arran', lastName: 'Taylor' }, { firstName: 'Alastair', lastName: 'Cook' }]; }]); </script> </body> </html>
Output