Search code examples
angulartypescriptangular-router

Angular Route dont call subscription when called itself


Following is my code, the subscription debugger hits first time when Page LOAD and component load first time , when button is clicked and search function is called. the subscription from nginit dont hit.

Any idea why

public search(): void {
    debugger;
    this.router.navigate(['/logs/error'], { queryParams: { file: this.searchQuery }});
}

ngOnInit() {
    this.sub = this.route.params.subscribe(params => {
        debugger; // (+) converts string 'id' to a number

        // In a real app: dispatch action to load the details here.
    });
}

Solution

  • If you want to track when the query parameters change, you need to use

    this.route.queryParams.subscribe(...)
    

    Not params