AngularJS Tutorial - Set selected value in select element








The following code shows how to set selected value in select element.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--   www  .ja v a2  s  . co  m-->
<body>
  <div ng-app ng-controller="MyCtrl">
    <select ng-model="referral.organization" ng-options="c for c in organizations"></select>
</div>
<script type='text/javascript'>
function MyCtrl($scope) {
    $scope.organizations = ['a', 'b', 'c', 'd', 'e'];
    $scope.referral = {
        organization: $scope.organizations[2]
    };
}
</script>
</body>
</html>

The code above is rendered as follows: