本身调用时,Angular Route不呼叫订阅 [英] Angular Route dont call subscription when called itself

查看:58
本文介绍了本身调用时,Angular Route不呼叫订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码,首次单击页面加载和组件加载时,单击按钮并调用search函数时,订阅调试程序将首次运行. nginit的订阅没有成功.

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.

知道为什么

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

推荐答案

如果您想跟踪 query 参数何时更改,则需要使用

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

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

不是 params

这篇关于本身调用时,Angular Route不呼叫订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆