Ng-Options-8

 

Ng-options create list of options using array of object "arrs" and selected option will display object because it is bind to names variable with ng-model directive.

 
 
 
<!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="names" ng-options="arr.name for arr in arrs"> <option value=''>--Select item--</option> </select> <pre>{{names | json}}</pre> </div> <script> var app = angular.module("Example", []); app.controller('ExampleController', ['$scope', function ($scope) { $scope.arrs = [{ name: 'Miller' }, { name: 'Clark' }]; }]); </script> </body> </html>
Output