Created
July 13, 2012 08:08
-
-
Save oborder/3103533 to your computer and use it in GitHub Desktop.
angularjs directive for bootstrap datepicker : eternicode/bootstrap-datepicker, eyecon.ro
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
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); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is sample of how to integrate bootstrap datepicker with angular.
use it like:
<input b-datepicker="{{dateoptions}}" ng-model="date" >
based on sample from Peter Bacon Darwin (jqUi)
https://github.com/petebacondarwin/angular-ui/tree/angular-v1.0/modules/directives/date