Angular Route 在调用自身时不调用订阅 [英] Angular Route dont call subscription when called itself

查看:27
本文介绍了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(...)

不是参数

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

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