Try to search your question here, if you can't find : Ask Any Question Now ?

RXJS Subject's value not updated on reloading page

HomeCategory: stackoverflowRXJS Subject's value not updated on reloading page
pragati asked 6 days ago

I have created a service which has a subject named selectedNode. I am trying to update the value of subject when I gives direct URL for loading a page. The issue is that the value of Subject is not updated when I tries to update the value directly when passing the URL.

e.g. if I opens URL localhost:4200/blog/page/subpage it should update selectedNode with value page/subpage. But, it does not.

My code is as below:


import {Component, OnInit} from '@angular/core';
import {BlogService} from '../../services/blog.service';
import {Router} from '@angular/router';

  selector: 'app-blog',
  templateUrl: './blog.component.html',
  styleUrls: ['./blog.component.css']
export class BlogComponent implements OnInit {

  constructor(private blogService: BlogService, private router: Router) {

  ngOnInit() {
    let routerURL = this.router.url;
    routerURL = routerURL.replace('/blog/', '');

Here the below code does not update the SelectedNode Subject. I checked while debug. The value is not updated in Subject despite of routerURL has a different value and the; is also called.

my blog.service.ts file is as follows:

import {Injectable} from '@angular/core';
import {Subject} from 'rxjs';
import {HttpClient} from '@angular/common/http';

export class BlogService {

  public selectedNode: Subject<string> = new Subject<string>();
  public sideNavDisabled: Subject<boolean> = new Subject<boolean>();

  constructor(private http: HttpClient) {

  public getTreeNodes() {
    return this.http.get('/assets/tree.json');

  public getPageContent(page: string) {
    return this.http.get('/assets/TreeStructure/' + page + '.html');

My complete code is present at
and can be viewed on

1 Answers
Best Answer
Matthias answered 6 days ago
Your Answer

9 + 6 =

Popular Tags

WP Facebook Auto Publish Powered By :