function MainCtrl() {
var vm = this;
vm.myDate = new Date();
vm.opened = false;
vm.format = 'dd-MMMM-yyyy';
vm.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
vm.myName = '';
vm.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
vm.opened = true;
};
// getDay() returns the day of the week. 0 = Sunday, 1 = Monday, etc.
vm.disabled = function(date, mode) {
return ( mode === 'day' && date.getDay() === 0 );
};
}
angular.module('plunker', ['ui.bootstrap'])
.controller('MainCtrl', MainCtrl);
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>Disable Sunday!</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.17/angular.js" data-semver="1.3.17"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.1/ui-bootstrap-tpls.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl as vm" class="container">
<div class="row">
<div class="col-xs-12">
<p>Selected Date is: {{ vm.myDate | date: 'yyyy-MM-dd' }}</p>
</div>
</div>
<div class="row">
<div class="col-xs-3">
<input type="text" ng-model="vm.myName" placeholder="What's your name?" />
</div>
<div class="col-xs-9">
<div>The angular controller says your name is: <b>{{ vm.myName || "N/A" }}</b></div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<p class="input-group">
<input type="text"
class="form-control"
datepicker-popup="{{vm.format}}"
ng-model="vm.myDate"
is-open="vm.opened"
ng-click="vm.open($event)"
datepicker-options="vm.dateOptions"
date-disabled="vm.disabled(date, mode)"
ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button"
class="btn btn-default"
ng-click="vm.open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
</body>
</html>
/* Put your css in here */
.row {
margin-top: 10px;
}
# Angular Bootstrap UI Datepicker
A simple use of Bootstrap UI's datepicker directive for Angular.
I display how to disable a specific day of the week as well. (in this case, Sundays)