Angularjs Examples

AJS Examples


AngularJS ng-Seleced Directive

The AngularJS ng-selected directive is used make selected option in select.

Syntax

<option ng-selected="selected">Value</option>

AngularJS ng-Seleced Directive Example

<html>
<head>
<title>My first AngularJS code</title>
<Script SRC="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js">
</Script>
<Script>
function appController($scope) {
    $scope.students = [
  {firstName:'Jimi', lastName:'Scotts', email:'jimi@xyz.com'},
  {firstName:'Paul', lastName:'Adam', email:'paul.a@xyz.com'},
  {firstName:'Peter', lastName:'England', email:'peter@xyz.com'},
  {firstName:'Rechard', lastName:'Jeff', email:'reachardjeff@xyz.com'}
];
$scope.makeSelected = $scope.students[2].email;
}
</Script>
</head>
<body>
<div ng-app ng-controller="appController">
Show Selected :<select ng-model="makeSelected" ng-options="student.email as (student.firstName + ' ' + student.lastName) 
for student in students"></select>
</div>

</body>
</html>
See Live Example