Skip to content

Instantly share code, notes, and snippets.

@mohitmamoria
Created September 19, 2013 10:10
Show Gist options
  • Save mohitmamoria/6621480 to your computer and use it in GitHub Desktop.
Save mohitmamoria/6621480 to your computer and use it in GitHub Desktop.
AngularJS directive for jQueryUI Datepicker
<html ng-app="myApp">
<body ng-controller="ProfileCtrl">
<script src="angular.js"></script>
<script src="DatePicker.js"></script>
<script>
angular.module('myApp').controller('ProfileCtrl', ['$scope', function($scope) {
$scope.dateOfBirth = '';
}]);
</script>
<input type="text" class="date-picker" ng-model="dateOfBirth">
</body>
</html>
'use strict';
angular.module('myApp')
.directive('DatePicker', function () {
return {
restrict: 'C',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
element.datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
onSelect: function(dateValue) {
scope.$apply(function() {
ngModel.$setViewValue(dateValue);
});
}
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment