'Getting paramMap data from another component that is not in the current route (ActivatedRoute) in Angular

Here is my code using paramMap within component A with the activatedRoute and it works fine


  ngOnInit(): void {

    this.route.paramMap.subscribe((params) => {
      this.id = <string>params.get('pid');
      
      this.projectService
        .get(this.id)
        .subscribe((project) => (this.project = <Project>project))
    })
  }

Now below it, I am trying to get the paramMap from another component B that is not in the activatedRoute and it is therefore returning null values.

    this.route.paramMap.subscribe((params) => {
      let id = params.get('categoryId');

      this.categorySub = this.projectService
        .getProjectCategory(id)
        .subscribe((category) => {
          this.category = category;
        });

Can anyone give me some clues on what I could do so that I can get access to component B?

Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source