In my Ionic 2 application, I have a feature that allows users to schedule notifications as reminders. The requirements for this feature are as follows:
- Upon entering the reminder page, it should check if there is a saved reminder.
- If a reminder is saved (currently using storage for this), the clock should display the saved reminder time and the toggle in an active state.
- If no reminder is saved, the clock should display the current time with the toggle deactivated.
This functionality works well, allowing me to save and disable reminders easily. However, I encounter an issue when there is a saved reminder and I navigate to the page. It triggers a notification stating "Reminder saved" every time I enter the page because the toggle automatically activates upon detecting a saved reminder. This leads to accidentally saving the reminder again.
I tried switching from using the (ionChange)
event to the click
event, but it did not solve the problem.
The relevant code snippets are shown below:
HTML:
<ion-content padding>
<div class="selector">
<ion-item>
<ion-label>Recordatorio</ion-label>
<ion-toggle class="toggle" [(ngModel)]="toggleStatus" checked="true" (click)="changeToggle()"></ion-toggle>
</ion-item>
<ion-item>
<ion-label>Horario</ion-label>
<ion-datetime
pickerFormat="HH:mm"
[(ngModel)]="time"
(ngModelChange)="timeChanged()"
cancelText="Cancelar"
doneText="Aceptar">
</ion-datetime>
</ion-item>
</div>
</ion-content>
Typescript:
ionViewWillEnter(): void {
this.setDefaultProperties();
}
public setDefaultProperties(): void {
// Code for setting default properties goes here
}
// More typescript functions go here...
In essence, I want to prevent the unintentional saving of reminders each time I visit the page. Any suggestions or alternative approaches would be greatly appreciated. Thank you!