There are some real bugaboos in setting up this tempermental little control. First, remove any ngModal binding expressions on the input controls. These will blow up your attempts to set and show the default value. Instead, use @ViewChild to get at the value when you need it. Second, if your control is going to be in a modal popup component that's not visible during the initial load, you may run into more issues. I could never get the element.data("DateTimePicker") / element.data("datetimepicker") to ever initialize or become available prior to displaying the control. It's simply not there. Third, set the locale. This seems to help a ton with the initial display regardless of the format. (Maybe I'm just superstitious. Getting this to work seemed like voodoo :)
In the end, I set up a proper TypeScript import with my own datepicker.d.ts and datepicker.js files that contained functions for initializing a control. My function is as follows in my datepicker.js:
export function datepickerinit(t,d){
if(!d)
d=new Date();
var m=moment(d).format('MM/DD/YYYY');
var j=$('#'+t);
if(j.data('DateTimePicker')){
j.data('DateTimePicker').date(m); //this seems to never be true
}
else {
j.datetimepicker({
date:m,
defaultDate:m,
format: 'MM/DD/YYYY',
locale:'en-US',
viewDate:m
});
}
}
I end up with a the date picker displaying my default value before the user clicks. (When it wasn't working, I'd end up with a fully expanded GMT datetime string before the user clicked the picker.)
When my users click a button to do an action, I get the value from my ViewChild's nativeElement.value property.