AngularJS Tutorial - Hardcode selection option








The following code shows how to create a select with hardcoded selection option.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!-- w w  w  .  j a  va  2  s .  c om-->
<body>
  <div ng-app ng-controller="MyCtrl">
    <select ng-model="ampm" ng-options="currOption for currOption in ['AM', 'PM']"></select>
    AM/PM: {{ampm}}
</div>
<script type='text/javascript'>
function MyCtrl($scope) {
    $scope.ampm = (new Date().getHours()) >= 12 ? 'PM' : 'AM';
}
</script>
</body>
</html>

The code above is rendered as follows: