Skip to content

Instantly share code, notes, and snippets.

@SompalSingh
Created August 7, 2018 06:05
Show Gist options
  • Save SompalSingh/7a8bc875481f4603760ea6bef36788fa to your computer and use it in GitHub Desktop.
Save SompalSingh/7a8bc875481f4603760ea6bef36788fa to your computer and use it in GitHub Desktop.
jQuery UI Datepicker with AngularJS
<div id="wrapper" ng-app="myApp">
<p>{{datePicker || "00/00/0000"}}</p>
<input type="text" ng-model="datePicker" datepicker />
</div>
var myApp = angular.module('myApp', []);
myApp.directive("datepicker", function () {
return {
restrict: "A",
require: "ngModel",
link: function (scope, elem, attrs, ngModelCtrl) {
var updateModel = function (dateText) {
scope.$apply(function () {
ngModelCtrl.$setViewValue(dateText);
});
};
var options = {
dateFormat: "dd/mm/yy",
onSelect: function (dateText) {
updateModel(dateText);
}
};
elem.datepicker(options);
}
}
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
body {
background: #3568AD;
}
#wrapper {
font: 20px Calibri;
width: 100px;
margin: 0 auto;
}
<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
@SompalSingh
Copy link
Author

UI Date picker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment