I have a DateTime picker, and I need to display a short date composed of date and month parts for annual date, wich be saved into the storage. When I pass the selected date using ionChange, there is not any event returned to typescript !
There is the faulting template, it’s ok for displaying but failing with change event :
My method triggered by change event must save date to a storage :
change_dateValue()
{
this.myDate = this.BOUtils.getStringISOToDate(this.strDateCotisa);
// Save it in the storage
}
Moreover, there is my method to prefill the date :
public myDate:Date;
private fillDate()
{
let tzoffset:number = (this.myDate).getTimezoneOffset() * 60000; //offset in milliseconds
this.strDate = (new Date(_date.getTime() - tzoffset)).toISOString().slice(0,-1);
// String returned model is : "2017-02-28T17:31:37.996Z"
}
Ionic uses the ISO 8601 datetime format for its value. The value is simply a string, rather than using JavaScript’s Date object.
Don’t bind <ion-datetime> components to JavaScript Date objects. In fact, IMHO, don’t ever even use JavaScript Date objects. Bind them to ISO8601 strings.
If someone is still looking for the workaround, here is what you can do. Call the function on ionBlur function. But the thing is it will call when your input field gets out of focus, like when you have changed or not changed. So you have to check whether value has changed or not.
It will not call on input value’s change but on input field get’s blur (not focused)
Check this out as sample: