AngularJS Tutorial - ng-selected selects an option value








The following code shows how to use ng-selected to select an option value.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
function QuarterController($scope) {<!--from w  w  w  . j  ava2s .  c  o  m-->
    $scope.Quarter = 3;
}
</script>
</head>
<body>
  <div ng-app>
  <div ng-controller="QuarterController">
    <select name="quarter" ng-model="Quarter" ng-selected="Quarter" >
        <option ng-repeat="v in [1,2,3,4]" value="{{v}}">Q{{v}}</option>
    </select>
  </div>
</div>
</body>
</html>

The code above is rendered as follows: