Created
September 19, 2013 10:10
-
-
Save mohitmamoria/6621480 to your computer and use it in GitHub Desktop.
AngularJS directive for jQueryUI Datepicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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