Having trouble retrieving data in the service. Unable to subscribe to it from other components

userService.ts

 private APIUrl: string = environment.APIUrl;
  constructor(private inService: API,
    private httpClient: HttpClient) { }

  private _userDataDashboard$ = new ReplaySubject<UserDetailsDashboard>(1);


  getUserDetailsSubject(): Observable<UserDetailsDashboard> {
    return this._userDataDashboard$.asObservable(); 
    
  }


  refreshUserData(): Observable<void> {
    
      const headers = new HttpHeaders()
        .set('Authorization', 'Bearer ' + localStorage.getItem(AppConstants.TOKEN));
    return this.httpClient.get<any>(this.APIUrl, {headers: headers}).pipe(
      tap((response: any) => {
        // notify all subscribers of new data
        this._userDataDashboard$.next(response.data );
        
      })
    );
  }

I have invoked this method within a section where the user enters details: Profile.ts

submitBasicDetails(basicDetails: {}) {
    this.isLoading = true;
    this.inService.submitBasicDetails(basicDetails).subscribe(
      (response: any) => {
        this.userService.refreshUserData();
       
 )}

When I try to display the fullName parameter in Dashboard.html, it doesn't show up

<h1>Hi {{data.firstName}}</h1>

  

I'm seeking assistance in resolving this issue.

Answer â„–1

It is important to remember that you need to invoke the subscribe method on refreshUserData() because Observable won't emit any data until you subscribe to it. To update your submitBasicDetails function, you can make the following changes:

submitBasicDetails(basicDetails: {}) {
  this.isLoading = true;
  this.inService.submitBasicDetails(basicDetails)
  .pipe(
    switchMap((response: any) => this.userService.refreshUserData())
  )
  .subscribe()
})

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 Ghostly Glare of Doom: Ionic 2 Strikes on Android

While my application runs smoothly in the browser, I encounter an error when trying to run it on my device. The issue is as follows: 0 758771 log deviceready has not fired after 5 seconds. 1 758797 log Channel not fired: onDOMConte ...

What is the method to adjust the color of <pagination-controls>?

Seeking assistance with customizing the color of angular pagination from blue to a different hue. Any suggestions? https://i.stack.imgur.com/JjcWk.png I've experimented with various code snippets, but unfortunately, none have yielded the desired res ...

execute the node application using the .desktop file

Hello, I am attempting to launch an application in Linux by double-clicking it. I have come across the .desktop file as a solution (I need this method because the app will be deployed on a Raspberry Pi and users prefer not to use the terminal). Here is wha ...

Angular 7 - ALERT: Circular dependency identified:

Suddenly, a lightbulb went off in my head. I encountered two warnings while running ng serve: WARNING in Circular dependency detected: src\app\_services\ignore-interceptor.service.ts -> src\app\_services\index.ts -> sr ...

What is the best way to set up JSData with cookie-based sessions and CSRF headers?

In order to properly configure my JSData settings, I must include instructions for passing information related to cookie-based session authentication and CSRF headers. ...

Slow auto page refresh in local development for Angular2 on Windows can be quite frustrating

Recently diving into angular2 and following the heros tutorial from docs. Struggling with a sluggish development experience while working with angular2. It's taking approximately 5 seconds for angular2 to recognize changes in files, followed by anothe ...

Utilizing Express JS to make 2 separate GET requests

I am facing a strange issue with my Express API created using Typescript. The problem revolves around one specific endpoint called Offers. While performing operations like findByStatus and CRUD operations on this endpoint, I encountered unexpected behavior ...

Facing issues while trying to update Angular from version 12 to 13 due to conflicting peer dependencies

I'm in the process of upgrading an Angular project from version 12 to 13, following the guidelines provided on the Angular update website https://update.angular.io/?v=12.0-13.0. Before starting the upgrade procedure, this is how the package.json file ...

Struggling to assign the correct data type to a property in Typescript

I am encountering a TypeScript error with the following code. In this interface, the 'items' property can be either an object or an array depending on the code and response. I am unsure how to specify the datatype of 'array/object/any', ...

Struggling with resolving unresolved dependencies

I have encountered issues when updating npm packages during an upgrade process. It seems that angular/core has unmet dependencies, as indicated below. I am curious to know the meaning of symbols such as '+', '-', ' ` '? T ...

Making Angular2 Templates More Efficient with Array.prototype.filter()

I have a variable named networkInterface that includes an array called services. My objective is to create a checkbox input that indicates whether a specific service_id exists within the services array of the networkInterface. An illustration of JSON `int ...

Enhancing performance with React.memo and TypeScript

I am currently developing a react native application. I am using the Item component within a flatlist to display data, however, I encountered an error in the editor regarding the second parameter of React.memo: The error message reads: 'Type 'bo ...

What is the process of using TypeScript to import a constant exported in JavaScript?

In the environment I'm using typescript 2.6.1. Within react-table's index.js file, there is a declaration that looks like this: import defaultProps from './defaultProps' import propTypes from './propTypes' export const React ...

The package information could not be loaded from the registry due to an error: The "timeout" parameter must be in numerical form. Instead, it was received as a string ('100000')

Encountered an issue while trying to install Angular Material in my project: PS C:\Users\Avinash Kumar\Desktop\Projects\CRUD\Project 2\Library Management System\UI\UI\Frontend> ng add @angular/material â ...

How to determine the frequency of a specific word in a sentence using Angular 5

I need help finding a solution to count how many times a word appears in sentences. Input: k = 2 keywords = ["anacell", "cetracular", "betacellular"] reviews = [ "Anacell provides the best services in the city", "betacellular has awesome services", ...

The data path "" must not contain any extra properties, such as dryRun

Just recently, I updated my MAC to the newest version of Angular 6.0.4. Upon entering the following command in Terminal: ng new happiness I encountered the following error: Schematic input does not validate against the Schema: {"dryRun":false,"version": ...

What is the best way to explain a function that alters an object directly through reference?

I have a function that changes an object's properties directly: function addProperty(object, newValue) { object.bar = newValue; } Is there a way in TypeScript to indicate that the type of object is modified after calling the addProperty function? ...

Pass information from a child component to a parent component within a React.js application

Using the Semantic-UI CSS Framework, I have implemented a dropdown menu and want to be able to select an item from it and identify which item has been selected. While I can determine the selected item within the child component and set its state, I am faci ...

Encountering the 'Default setting for timestampsInSnapshots now set to true' error in Firestore console

Encountering a Firestore error in the console while using Angular. @firebase/firestore: Firestore (5.8.3): The timestampsInSnapshots setting now defaults to true and does not require explicit setting. It is advised to remove it from firestore.settings( ...

Struggling with the compilation of this Typescript code

Encountering a compile error: error TS2339: Property 'waitForElementVisible' does not exist on type 'signinPage' SigninPage code snippet: export class signinPage{ constructor(){ emailInput: { selector: 'input[type ...