Skip to content

Instantly share code, notes, and snippets.

@oborder
Created July 13, 2012 08:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save oborder/3103533 to your computer and use it in GitHub Desktop.
Save oborder/3103533 to your computer and use it in GitHub Desktop.
angularjs directive for bootstrap datepicker : eternicode/bootstrap-datepicker, eyecon.ro
angular.module('bDatepicker', []).
directive('bDatepicker', function(){
return {
require: '?ngModel',
restrict: 'A',
link: function($scope, element, attrs, ngModelCtrl) {
var originalRender, updateModel;
updateModel = function(ev) {
return $scope.$apply(function() {
return ngModelCtrl.$setViewValue(ev.date);
});
};
if (ngModelCtrl != null) {
originalRender = ngModelCtrl.$render;
ngModelCtrl.$render = function() {
originalRender();
return element.datepicker.date = ngModelCtrl.$viewValue;
};
}
return attrs.$observe('bDatepicker', function(value) {
var options;
options = {};
if (angular.isObject(value)) {
options = value;
}
if (typeof(value) === "string") {
options = angular.fromJson(value);
}
return element.datepicker(options).on('changeDate', updateModel);
});
}
};
});
@oborder
Copy link
Author

oborder commented Jul 13, 2012

this is sample of how to integrate bootstrap datepicker with angular.

use it like:
<input b-datepicker="{{dateoptions}}" ng-model="date" >

  • dateoptions is optional config object from controller

based on sample from Peter Bacon Darwin (jqUi)
https://github.com/petebacondarwin/angular-ui/tree/angular-v1.0/modules/directives/date

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