You could just do the trick, keeping the old value of EventStart. I added two code samples. The HTML code will be updated first, but it will only support the updated value if you click on confirmation, otherwise it will return the DatePicker value to the old value. The second will work as you expected, but I do not know your value. Item.EventStart looks like. I just think it looks like this '00:00' pattern. Code examples will cost you more than an explanation in words :).
First
public oldEventStart = this.item.EventStart; updateStartTime(startTime) { let alert = this.alertControl.create({ title: 'Change start time', message: 'Are you sure you want to update the start time for this event?', buttons: [ { text: 'Cancel', handler: () => { this.item.EventStart = this.oldEventStart; console.log('cancel'); } }, { text: 'Confirm', handler: () => { this.item.EventStart = startTime; this.oldEventStart = startTime; console.log(startTime); } } ] }); alert.present(); alert.onDidDismiss(() => { this.item.EventStart = this.oldEventStart; }); }
Second
public oldEventStart = this.item.EventStart; updateStartTime(startTime) { this.item.EventStart = new Date('2000-01-01T'+this.oldEventStart+':00.00').toISOString(); let alert = this.alertControl.create({ title: 'Change start time', message: 'Are you sure you want to update the start time for this event?', buttons: [ { text: 'Cancel', handler: () => { this.item.EventStart = this.oldEventStart; console.log('cancel'); } }, { text: 'Confirm', handler: () => { this.item.EventStart = startTime; this.oldEventStart = startTime; console.log(startTime); } } ] }); alert.present(); alert.onDidDismiss(() => { this.item.EventStart = this.oldEventStart; }); }
Hope this helps solve your problem. Hooray!.
source share