Maintaining checkbox selection while switching pages in Angular

When I try to edit the settings for accepting payments in all currencies under the "Pricing" component, the checkbox is unchecked every time I return to the "General" section. How can I prevent this from happening and keep the checkbox checked? Refer to the following links for images: 1, 2, 3.

 <div class="inline-vertical-align input-convert-values minimun-height">
                <div class="inputs-value-container">
                    <div class="big-value-container">
                        <mat-checkbox [disabled]="mode === 'view'" [checked]="active?.bothMandatory" (change)="onCheckBoxChange($event, '')" 
                        color="primary">{{ 'managePackages.bothMandatory' | translate }}</mat-checkbox>
                    </div>
                </div>
                <div class="inputs-value-container" *ngIf="active?.bothMandatory">
                    <p [ngClass]="{'disabled': mode === 'view'}" class="underline-button" (click)="distributeEqualy()" >{{ 'managePackages.distributeEqualy' | translate }}</p>
                </div>
            </div>
        
            <div class="inline-vertical-align input-convert-values minimun-height">
                <div class="inputs-value-container">
                    <div class="big-value-container">
                        <mat-checkbox [disabled]="active?.bothMandatory || mode === 'view'" [checked]="active?.acceptBnb || active?.bothMandatory"
                        color="primary" (change)="onCheckBoxChange($event, 'BNB')">BEP20 - Binance</mat-checkbox>
                    </div>
                </div>
                <div class="inputs-value-container" *ngIf="active?.bothMandatory">
                    <div class="big-value-container">
                        <input [disabled]="mode === 'view'" (keydown.ArrowDown)="blockNegativeNumber($event, $event.target.value)" type="text" 
                        class="input big-value" (input)="verifyCompleteData()" [(ngModel)]="bnbPrice" placeholder="00,0%"
                        appMaskPercentual>
                    </div>
                </div>
            </div>
        
            <div class="inline-vertical-align input-convert-values minimun-height">
                <div class="inputs-value-container">
                    <div class="big-value-container">
                        <mat-checkbox [disabled]="active?.bothMandatory || mode === 'view'"  [checked]="active?.acceptCoin || active?.bothMandatory"
                        color="primary" (change)="onCheckBoxChange($event, 'Coin')" >TOKEN</mat-checkbox>
                    </div>
                </div>
                <div class="inputs-value-container" *ngIf="active?.bothMandatory">
                    <div class="big-value-container">
                        <input [disabled]="mode === 'view'" (keydown.ArrowDown)="blockNegativeNumber($event, $event.target.value)" type="text" 
                        class="input big-value" (input)="verifyCompleteData()" [(ngModel)]="coinPrice" placeholder="00,0%"
                        appMaskPercentual>
                    </div>
                </div>
            </div>

Answer №1

One effective way to share data between components is by utilizing a service to store the information, ensuring it remains accessible even when navigating between different routes.

To achieve this, you can establish a binding between the value of a checkbox and a variable that is initialized within the shared service.

For a more detailed explanation, I have provided a demonstration on StackBlitz.

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

The process of expanding a nested node in the Angular Material tree with deeply nested data

Within my Angular 7 application, I am utilizing a mat tree structure that contains nested array objects. The goal is to automatically expand specific nested sections after users make changes to the data within those sections. While I have successfully exp ...

What are the best techniques for streamlining nested objects with Zod.js?

As a newcomer to zod.js, I have found that the DataSchema function is extremely helpful in verifying API data types and simplifying the API response easily. However, I'm curious if there is a way to streamline the data transformation process for myEx ...

Tips for utilizing the value of object1.property as a property for object2

Within the template of my angular component, I am attempting to accomplish the following: <div> {{object1.some_property.(get value from object2.property and use it here, as it is a property of object1)}} </div> Is there a way to achieve this ...

The issue with Angular's Mat Option selected values not functioning properly

We have a scenario where there are two form fields, and the second field needs to be disabled or enabled based on the selected value from the first field. The first field contains 5 values: 'a', 'b', 'c', 'd', ' ...

Uh oh! An issue occurred: StaticInjectorError(AppModule)[UserformService -> HttpClient] - There seems

After attempting to incorporate a PrimeNG table into my project, I encountered issues with my build. You can view the broken state of my code at https://github.com/BillyCharter87/Tech-O-Dex-UI/tree/BrokeIt I believe the problem arose when I updated my pac ...

The reason for the Jest failure is that it was unable to locate the text of the button

As someone who is new to writing tests, I am attempting to verify that the menu opens up when clicked. The options within the menu consist of buttons labeled "Edit" and "Delete". However, the test fails with the message: "Unable to find an element with te ...

What issues can trailing white space cause in TypeScript coding?

While I understand that linting is the reason for this, why are trailing spaces considered problematic? I plan to disable this feature in tslint.json, but before I make that change, I want to ensure I'm not making a mistake. Visual Studio Code alert ...

implement a solution in Ionic 4 Angular 6 that triggers a function only when all the observables in a loop have

In my code, I have a function named getDevices(). This function is responsible for fetching an array of devices. After getting this array, the code iterates through each device and calls another function called updateToServer(). The purpose of updateToServ ...

Encountering a problem in a MEAN application while sending a PUT request

I am encountering an issue while developing a todos app in MEAN stack with MongoDB installed locally. The error I am facing is related to the PUT request. Any assistance on resolving this problem would be greatly appreciated. Error: Argument passed in mus ...

Exploring the use of national flag emojis in VS code

I've been attempting to use flag emojis as reactions on a Discord bot, but they just won't cooperate. Every time I try something like this > ':flag_jp:', I encounter the following error: Error: DiscordAPIError: Unknown Emoji EDIT ...

Error: npm encountered a loop error while attempting to download

Looking to implement Google login, I attempted the following command: npm install --save angularx-social-login. Unfortunately, it returned an error: D:\proj>npm install --save angularx-social-login npm ERR! code ELOOP npm ERR! syscall open npm ERR ...

Having difficulty initializing a constant object in TypeScript

Encountering an error while attempting to compile my code using Angular 7.2.0 and TypeScript version 3.2.2: Error TS1005: ',' expected.**… The issue seems to be arising from the line where I am trying to define a const object. addAppareil( ...

Type definition for Vuex store functionality

Working on creating a versatile type to provide typing hints for mutations in Vuex. After reading an inspiring article on Vuex + TypeScript, I decided to develop something more generic. Here is what I came up with: export type MutationType<S, P, K exten ...

Transforming TimeZone Date Object without Altering Time

I am looking to change the time zone of a date from one timezone to another. For example: "Sun May 01 2019 00:00:00 GMT+0530 (India Standard Time)" is the current date object. I want to convert this date based on a specific timeZone offset, let's say ...

Exploring observables for querying the OMDB API and obtaining information on movies

Hey everyone, I'm currently working on implementing a live search feature using Observables in Angular2 to fetch Movie data from the OMDB API. While I can see that it is functioning correctly in the Chrome Network tab, the results aren't showing ...

How can Angular developers properly implement token refreshing in their applications?

Recently, I've been struggling with implementing a logic in my code. I have a specific requirement: Whenever there is a signed request (signed - means it has a JWT token for authenticated users) made to the API backend, the API backend may respond w ...

Tips for continuously running a loop function until retrieving a value from an API within a cypress project

Need help looping a function to retrieve the value from an API in my Cypress project. The goal is to call the API multiple times until we receive the desired value. let otpValue = ''; const loopFunc = () => { cy.request({ method: &ap ...

Choosing Vue select options depending on a condition

I am working on a dropdown template with Vue.js and have encountered some challenges. Here is the basic structure of my dropdown: <select v-model="selectedClient" class="stat-select text-u-c"> <option disabled value="">Please select a Client ...

Deciphering the TypeScript type in question - tips and tricks

One of my abstract classes includes a static property with various properties, where default is consistently named while the others may have random names. public static data = { default: { //only this one always have 'dafault' name na ...

`Express routes in TypeScript`

Recently, I have been following a tutorial on how to build a Node.js app with TypeScript. As part of the tutorial, I attempted to organize my routes by creating a separate route folder and a test.ts file containing the following code: import {Router} fro ...