Hardcode selection option

Description

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><!--from  ww  w .j  ava  2s.  co m-->
<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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities