I spent some time researching the existing datetime angular symbol directives.
Both ngularUI and AngularStrap do not provide a datetimepicker as needed. Of course, I know how to use datepicker and timepicker to archive the target.
I searched for a relevant topic from the Internet and stackoverflow. Found interesting and useful information.
http://dalelotts.imtqy.com/angular-bootstrap-datetimepicker/ , there is a datetimepicker, but I do not like the use of this directive.
connecting datetimepicker to angularjs , this topic is very useful, I tried to wrap my datetimepicker directive by following these steps.
My work is based on https://github.com/Eonasdan/bootstrap-datetimepicker , based on datetimepicker based on bootstrap 3, the user interface is very nice.
app.directive('datetimepicker', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
console.log('call datetimepicker link...');
var picker = element.datetimepicker({
dateFormat: 'dd/MM/yyyy hh:mm:ss'
});
ngModelCtrl.$render(function() {
console.log('ngModelCtrl.$viewValue@'+ngModelCtrl.$viewValue);
picker.setDate(ngModelCtrl.$viewValue || '');
});
picker.on('dp.change', function(e) {
console.log('dp.change'+e.date);
scope.$apply(function(){
ngModelCtrl.$setViewValue(e.date);
});
});
}
};
});
And use it in my view.
<div class="col-md-6">
<div class="input-group date" id="endTime" data-datetimepicker ng-model="stat.endTime" data-date-format="MM/DD/YYYY hh:mm A/PM" >
<input class="form-control" type="text" placeholder="End"/>
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
There are some problems that I have found.
- If the date is set using json before rendering in the view, the start date is not displayed, I do not see any ngModel rendering method execution log.
- When I selected the date, it got the date and time based on json data, not the long format. And in another related snippet in the view, row-based date cannot be parsed using the angular date filter.
- When used in a modal dialog box, this value is not cleared the next time the modal window appears.
Thanks in advance.