// Controller
this._display = 'HH:mm';
this._picker = 'HH:mm';
this._control = /* Basic angular form control with value */
// View
<ion-datetime [displayFormat]="_display" [pickerFormat]="_picker" [formControl]="_control"></ion-datetime>
If this._control.value
is null, I would like the picker to display a time that is 3 hours in the future without setting this._control.value
.
Is there a way to accomplish this?
I have tried to follow the steps of https://forum.ionicframework.com/t/ionic-ion-datetime-how-to-set-default-picker-value-without-changing-the-model/74156/4
, but it does not work:
// Controller
setDefaultDate() {
this._tmpDefaultDate = moment().add(3, 'hours').format('YYYY-MMM-DD HH:mm:ss');
}
cancel() {
if(!this._control.value) {
this._tmpDefaultDate = '';
}
}
// View
<ion-datetime [displayFormat]="_display" [pickerFormat]="_picker" [formControl]="_control" [(ngModel)]="_tmpDefaultDate" (ionCancel)="cancel()" (tap)="setDefaultDate()"></ion-datetime>