Skip to content

Instantly share code, notes, and snippets.

@anilsingh581
Forked from HasAndries/gist:3135128
Last active August 29, 2015 14:18
Show Gist options
  • Save anilsingh581/0b62de647e7dc6d9fab7 to your computer and use it in GitHub Desktop.
Save anilsingh581/0b62de647e7dc6d9fab7 to your computer and use it in GitHub Desktop.
angular.module('bDatepicker', []).
directive('bDatepicker', function(){
return {
require: '?ngModel',
restrict: 'A',
link: function($scope, element, attrs, controller) {
var updateModel;
updateModel = function(ev) {
element.datepicker('hide');
element.blur();
return $scope.$apply(function() {
return controller.$setViewValue(ev.date);
});
};
if (controller != null) {
controller.$render = function() {
element.datepicker().data().datepicker.date = controller.$viewValue;
element.datepicker('setValue');
element.datepicker('update');
return controller.$viewValue;
};
}
return attrs.$observe('bDatepicker', function(value) {
var options;
options = {};
if (angular.isObject(value)) {
options = value;
}
if (typeof(value) === "string" && value.length > 0) {
options = angular.fromJson(value);
}
return element.datepicker(options).on('changeDate', updateModel);
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment