Skip to content

Instantly share code, notes, and snippets.

@allenhwkim
Created June 16, 2015 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allenhwkim/72add6443019bfbe0f88 to your computer and use it in GitHub Desktop.
Save allenhwkim/72add6443019bfbe0f88 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="angular.js"></script>
<script>
angular.module('myApp', []).
factory('datepicker', function($compile, $document){
var datepickerEl, datepickerElCtrl;
return {
open: function(options) {
var div = angular.element('<div datepicker></div');
div.attr({ 'date-format': options.dateFormat });
datepickerEl = $compile(div)(options.element.scope());
div.remove();
$document.find('body').append(datepickerEl);
datepickerElCtrl = datepickerEl[0].datepickerCtrl;
datepickerElCtrl.open(options);
},
close: function(options) {
datepickerEl.remove();
}
}
}).
directive('datepicker', function(){
var datepickerCtrl = function() {
this.open = function(options) {
};
};
return {
scope: {},
controller: datepickerCtrl,
template: 'DATETIME PICKER',
link: function(scope, element, attrs, ctrl) {
element[0].datepickerCtrl = ctrl;
}
};
}).
directive('openDatepicker', function($parse, datepicker) {
return {
link: function(scope, element, attrs) {
datepicker.open({
element: element,
dateFormat: attrs.dateFormat
})
}
}
})
</script>
</head>
<body ng-app="myApp">
<input ng-model="myDate" open-datepicker="" date-format="yyyy-MM-dd" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment