What could be causing the disappearance of my Angular 6 Service object variable upon refreshing the component it's injected into?

Recently, I encountered an issue with a SERVICE named test.service, which contains an object:

 public locationObject = {
   ......
   ......
   currency: string
}

In my project, this SERVICE is injected into the HeaderComponent and the object locationObject is initialized in ngOnInit. Everything seems fine, but when a user logs in, I use router.navigate to redirect them to a dashboard.

 ..
this.router.navigate(['owner-dashboard']);

The same SERVICE is also injected into the loginComponent and ownerDashboardComponent, allowing me to access the properties of locationObject in the ownerDashboardComponent. However, upon refreshing the screen, I noticed that locationObject becomes undefined. Additionally, after some time, the header component refreshes itself and resets the locationObject. This raises questions about why I lose locationObj despite the refreshed header.

I have a vague understanding of what might be happening here, but I would appreciate it if someone could explain it to me. Thank you.

EDIT. core html:

Answer №1

If you want to avoid browser refresh, consider utilizing local storage or a similar method to store the variable data locally.

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

What is the best way to implement a late-binding clone method in TypeScript classes?

Creating a simple Cloneable interface for all my data classes in JavaScript is a straightforward task. However, when it comes to typing it properly in TypeScript, things get a bit more complex. Currently, I am putting together a solution like this: class ...

Customize CSS styles based on Angular material stepper orientation

Is it possible to change the CSS style of an angular material stepper based on its orientation? For instance, can we set a red background when the stepper is displayed vertically and a blue background when horizontal? ...

Tips on applying border to unique marker icon in Angular2 using agm-marker

https://i.sstatic.net/HH36B.png Hello everyone, I've been working on a project and need some assistance. My goal is to dynamically add custom marker icons to specific lat/lng coordinates, each with additional values such as a "color name" for border ...

Tips for implementing react-select types in custom component development

Currently, I'm in the process of developing custom components for DropdownIndicator to be used on react-select with Typescript. However, I am encountering difficulties with the component's type due to my limited experience with Typescript. I wou ...

Angular Drag and Drop with Multiple Items (ng2-dragula)

Currently searching for a drag and drop library that can handle multiple drag capabilities. Unfortunately, none have been found specifically for Angular 2+. While ng2-dragula does meet some of our requirements, it falls short when it comes to supporting ...

White Background Dialog in Angular

I am struggling to change the default white background of my webpage. Is there a way I can use CSS to blur or darken the background instead? I tried applying CSS code but couldn't locate the correct class. I also attempted setting the "hasBackdrop" at ...

Utilizing React-select Props Typings: A Guide

I'm currently working on creating a component that wraps the AsyncSelect, but I've run into an issue with their props having generics, and I'm not sure how to approach this. Below you'll find my code snippet: export class PipTagSelect ...

Failure in Dependency Injection in Angular with Typescript

My mobile application utilizes AngularJS for its structure and functionality. Below is the code snippet: /// <reference path="../Scripts/angular.d.ts" /> /// <reference path="testCtrl.ts" /> /// <reference path="testSvc.ts" /> angular.mo ...

Bring in typings from a package with an alternate title

I have a project that I am currently converting to typescript. In this project, I am using the package ng-idle. Additionally, there is a corresponding @types package named angular-idle, which contains the file @types/angular-idle/index.d.ts with the follow ...

The checkbox confirmation button appears to be absent in the ngx mat date time picker

I encountered a styling issue with the ngx mat datetime picker in my Angular 15 project. You can find the package here. To resolve the issue, I included @import "https://fonts.googleapis.com/icon?family=Material+Icons"; in my styles.scss file, and that re ...

The ts-loader seems to be malfunctioning (It appears that a suitable loader is required to handle this file type, as no loaders are currently set up to process it)

I'm currently in the process of integrating TypeScript into a JavaScript project, but it seems like webpack is not recognizing the ts-loader for files with the .tsx extension. I've attempted to use babel and even tried awesome-ts-loader, but none ...

"Unlocking the treasure trove: Extracting a single item from my Firebase real-time database using

Searching for the user's article in my Realtime database to display information. https://i.sstatic.net/yCdgf.png This is my Ionic script page Below are the imports I have: I am able to retrieve the user's ID, but I'm facing difficulty in ...

Declaring an array that holds Angular components in Angular 11: What's the best approach?

I'm trying to implement a feature in my Angular component where I can create a list that displays content from other components. My current approach involves declaring an array that contains references to different Angular components: import { Compone ...

How to easily update a URL string in Angular 5 router without altering the state of the application

I am working on an Angular 5 application that utilizes the angular router. The majority of my entry route components are placed under a context id, which represents a name in the app store along with other relevant data for that context. Even though the na ...

Guide on incorporating text input areas into specific positions within a string

Looking for a way to replace specific words in a string with input fields to enter actual values? For example... Dear Mr. [Father_name], your son/daughter [name] did not attend class today. This is what I want it to look like... Dear Mr. Shankar, your ...

Dealing with CORS and multiple headers

After setting up CORS for my web api project and deploying it to local IIS, I encountered an issue when trying to call a controller method from Angular. The error message displayed was as follows: SEC7128: Multiple Access-Control-Allow-Origin headers ar ...

Issue: Dependency type ContextElementDependency does not have a corresponding module factory available

After cloning the project from GitLab and running npm install, all dependencies were successfully downloaded. However, upon executing npm start, I encountered an error stating "No module factory available for dependency type: ContextElementDependency." In ...

Angular function is executed ahead of the designated schedule

I am working with Angular components that execute two functions during initialization. The first function populates an array, and the second function takes values from that array and calls a service. The issue I am facing is that the second function execu ...

During the ng build process, an error is encountered stating, "Cannot read the property 'kind' of undefined."

Currently, I am working on a project that requires me to utilize ng build --prod in order to build a client. However, each time I run ng build --prod, I encounter the same persistent error message: ERROR in Cannot read property 'kind' of undefin ...

Exploring the concept of TypeScript's Array Union

I've been exploring Typescript union and encountered an issue when assigning an array with the type number[] | string[]. Whenever I try to push a string or number into it, I receive the error message "Argument of type 'string' is not assigna ...