ionChange - only detect changes made in the view and update the model in Ionic 2

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!

Answer №1

The issue was resolved by utilizing: (ngModelChange) in place of (ionChange)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for implementing *ngFor directive in an Angular child component to generate a table

My goal is to showcase a table of users by incorporating the <tr> tag within a loop using (*ngFor). In UserComponent.html: <div class="theme-2"> <div class="example-container mat-elevation-z8"> <app-user *ngFor="let user of use ...

Error! Unable to find a compatible version for elements@~0.1.2

Just starting out with Angular and ran into an issue while trying to install packages using 'npm install'. I received the following error message and am unsure how to fix it: npm ERR! notarget No matching version found for elements@~0.1.2. npm ...

Generating data types based on the output of functions

I'm currently working on optimizing my typescript react code by reducing repetition. I'm curious to know if there's a way to generate a type based on the return type of a known function? For example: const mapStateToProps = (state: StoreSt ...

Having difficulty resolving rxjs issue

Compilation failed. Failed to locate module './rxjs/Observable/of' in 'C:\Users\Admin\angular\myheroes\src\app' @ ./src/app/hero.service.ts 13:11-40 @ ./src/app/app.module.ts @ ./src/main.ts @ multi ...

Ways to identify modifications from a BehaviorSubject and automatically trigger a response according to the updated value

I am currently implementing a BehaviorSubject for managing languages in my Angular project. I am also utilizing Angular Datatables and trying to dynamically change the language displayed in the data table based on the value returned from the subscription. ...

Inefficiency in POST method prevents data transmission to MongoDB

I've developed a MERN application and now I'm testing the backend using the REST client vscode extension. This is how it looks: `POST http://localhost:4000/signup Content-Type: application/json { "email": "<a href="/cdn-cgi ...

Sharing information with child components in Angular

I am currently working with Angular and I have two child components that I need to pass data to. In the home template, my code looks like this: <div class="myCard"> <mat-card style="width: 500px;"> <mat-card-tit ...

Encountering a challenge when upgrading to eslint version 9.0.0

Encountering an issue while trying to upgrade eslint to version 9.0.0. ⋊> ~/A/fusion on turborepo ⨯ bun lint 22:21:58 $ eslint packages/*/src/**/* Oops! Something went wrong! :( ESLint: 9.0. ...

The successful conversion of Typescript to a number is no longer effective

Just the other day, I was successfully converting strings to numbers with no issues. However, today things have taken a turn for the worse. Even after committing my changes thinking all was well, I now find that when attempting to cast in different ways, I ...

"Exploring the New Feature of Angular 17: Named Router Outlets Implemented

One issue I am facing with my application is the rendering of different pages based on whether a user is logged in or not. The generic pages like the landing or logout page should be displayed within the primary router-outlet when the user is not logged in ...

Tips for sending Angular objects to the backend using a GET request?

I am encountering an issue when attempting to pass custom objects from Angular to the backend using a GET request. When using custom objects in the backend, I am receiving null values for all properties. What are the correct methods for passing objects in ...

What is the best way to extract items from another array that have approved IDs - is it through using map(), filter(),

I am unsure about the best approach to retrieve only the items (array with objects) that have been approved based on their id. Should I start by using map() and then filter(), or should I filter() them first and then map()? export class AppComponent { ...

Tips for minimizing Firestore reads by utilizing cache efficiently

I am facing a challenge with managing a large list of trips data ordered by date. Current Approach Previously, I would store all the trip data in a SqlLite Db. Whenever new data was added, I would receive an fcm notification and only sync the newly added ...

What is the best way to compare dates for a deadline using Angular and CSS?

Having recently delved into Angular 8, I just picked up on how to convert timestamps to strings using interpolation and .toMillis. However, I am looking to enhance this feature in my project app. I'm currently working on comparing the date saved in m ...

Guide to automatically installing @types for all node modules

As a newcomer to Typescript and NodeJs, I have been experiencing errors when mentioning node modules in my package.json file and trying to import them. The error messages I always encounter are as follows: Could not find a declaration file for module &apos ...

Returns false: CanActivate Observable detects a delay during service validation

Issue with Route Guard in Angular Application: I encountered an issue with my route guard in my Angular application. The problem arises when the guard is active and runs a check by calling a service to retrieve a value. This value is then mapped to true or ...

The server is unable to decode the JSON file

I've developed an Android app that needs to interact with my website using JSON. The JSON format on the client side of Android is as follows: private static String JSONSend(Context ctx, JSONObject obj, String ObjName, String address) { IHttpDispat ...

Persistent session cookies on mobile Chrome browsers

My application sets a session cookie at the start of each request. While this cookie is supposed to clear when the browser is closed, I've noticed that it doesn't always work as expected on Chrome for Android or iPhone. It seems like the mobile ...

Is it possible to reset the attributes of a container's children using a renderer?

Within a container, there are dropdowns, multiple selects, and quantity selections. When a button is clicked, I aim to reset the state of the component. https://i.stack.imgur.com/TY5un.png <input #select type="checkbox" value="somevalue"/> The ...

Approach to Monitoring Notifications

Is there a best practice for managing notifications in an AngularJS application? When I mention 'notifications', I am referring to alerts that should be displayed to the user while they are logged into the app. My idea is to show the user any u ...