2

I am using ActivatedRoute and subscribing to its params to get triggered. But, the subscription is not triggering.

Code:

constructor(public activatedRoute: ActivatedRoute) { 
    this.activatedRoute.params.subscribe((params : any) => {
        console.log(params);
    });
}

I am unable to know the issue. Please help me solve this.

Thank you...

Sai M.
  • 2,548
  • 4
  • 29
  • 46

2 Answers2

1

I am using the same in ngOnInit() and it works..

You have syntax error i guess..(subscribe parenthesis)

 this.activatedRoute.params.subscribe(params => {
        console.log(params);

       //call function here for data change
    });
Abdul Rasheed
  • 6,486
  • 4
  • 32
  • 48
Rajat Gupta
  • 568
  • 1
  • 6
  • 19
1

you are missing queryParams:

import { ActivatedRoute } from '@angular/router';
...
constructor( private _route: ActivatedRoute ) { }
...
ngOnInit() {
    this._route.queryParams            
        .subscribe(
        params => {                
            console.log(params);           
        });
}
Joe Belladonna
  • 1,349
  • 14
  • 20