Sai
Sai

Reputation: 2668

Subscription to route params not triggering

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...

Upvotes: 2

Views: 2786

Answers (2)

Joe Belladonna
Joe Belladonna

Reputation: 1339

you are missing queryParams:

import { ActivatedRoute } from '@angular/router';
...
constructor( private _route: ActivatedRoute ) { }
...
ngOnInit() {
    this._route.queryParams            
        .subscribe(
        params => {                
            console.log(params);           
        });
}

Upvotes: 1

Rajat Gupta
Rajat Gupta

Reputation: 578

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
    });

Upvotes: 1

Related Questions