Angular Route dont call subscription when called itself

霸气de小男生 提交于 2019-12-08 11:37:09

问题


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

回答1:


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

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

Not params



来源:https://stackoverflow.com/questions/46934833/angular-route-dont-call-subscription-when-called-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!