Last active
December 26, 2015 05:29
-
-
Save allenyang79/7101243 to your computer and use it in GitHub Desktop.
angular +bootstrap datetime picker
This file contains hidden or 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
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://dl.dropboxusercontent.com/u/7963854/css/bootstrap-datetimepicker.min.css"> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script> | |
<script src="https://dl.dropboxusercontent.com/u/7963854/js/bootstrap-datetimepicker.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.7/angular.min.js"></script> | |
<div class="input-append date form_datetime"> | |
<input size="16" type="text" value="" readonly> | |
<span class="add-on"><i class="icon-th"></i></span> | |
</div> | |
<div ng-app="app"> | |
<div ng-controller="Ctrl" ng-init="mydate='1234'"> | |
<div datetime-picker ng-model="mydate"></div> | |
my date is {{mydate}} | |
</div> | |
</div> |
This file contains hidden or 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
$(".form_datetime").datetimepicker({ | |
format: "dd MM yyyy - hh:ii", | |
autoclose: true, | |
todayBtn: true, | |
pickerPosition: "bottom-left" | |
}); | |
console.log("run"); | |
var app=angular.module("app",[]) | |
console.dir(app) | |
app.controller("Ctrl",function($scope){ | |
console.log("Ctrl run") | |
}) | |
app.directive("datetimePicker",function(){ | |
var tpl='<div><div class="input-append date datetime">'; | |
tpl+='<input size="16" type="text" value="" readonly>'; | |
tpl+='<span class="add-on"><i class="icon-th"></i></span>'; | |
tpl+='</div></div>'; | |
return { | |
restrict:"EA", | |
scope:{ | |
ngModel:"=" | |
}, | |
replace:true, | |
template:tpl, | |
link:function(scope,element,attr){ | |
console.log($(".datetime",element).size()) | |
$(".datetime",element).datetimepicker({ | |
format: "yyyy-mm-dd hh:00:00", | |
minuteStep :15, | |
viewSelect :"day", | |
autoclose: true, | |
todayBtn: false, | |
pickerPosition: "bottom-left" | |
}).change(function(){ | |
alert($("input",this).val()) | |
scope.ngModel=$("input",this).val() | |
$(this).datetimepicker('hide') | |
scope.$apply(); | |
}); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment