Search code examples
angularionic4angular7-router

How to pass data from one page to another page using angular fragments?


I'm trying to send data another page while navigating to another page.

this.router.navigateByUrl('/homePage', { fragment:"hello world"});

I'm not sure how to receive my fragment inside my homepage. what i have tried his below here in my homepage.

ngOnInit() {
    this.router.fragment.subscribe((fragment: any) => {
      console.log("My hash fragment is here => ", fragment)
    })
}

I'm getting undefined i'm not sure how to receive the fragment any help...


Solution

  • I am able to print the console.log in my home page by changing the below

    this.router.navigateByUrl('/homePage', { fragment:"hello world"});
    

    to this

    this.router.navigate(['parameter-to-device'], { fragment:"hello world"});