How to handle multiple queryParams in Angular2

后端 未结 2 1686
花落未央
花落未央 2021-01-13 11:54

I\'m trying to implement a filtering mechanism in a new Angular2 app, that would allow me to filter a list of entries in an array. The entries may have around 20 properties

2条回答
  •  逝去的感伤
    2021-01-13 12:16

    Try this.

    this.router.navigate(['/findlist'], { queryParams: { param1: 'value1', 'param2': 'value2' } }); 
    

    and then the url would look like

    localhost:4200/findlist?param1=value1¶m2=value2 
    

    Finally, you could get back the route params by using the snippet below,

    this.route.queryParams.subscribe((p: any) => {
        if (p.param1){
            console.log(JSON.parse(p.param1));
        }
     if (p.param2){
            console.log(JSON.parse(p.param2));
        }
    });
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题