问题
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