Extract id from url using Angular2

后端 未结 6 927
有刺的猬
有刺的猬 2021-02-03 17:57

Hi I am trying to extract the id part of the url using Angular2.

http://localhost:3000/item/187809

I have been playing around with ActiveRoute

6条回答
  •  伪装坚强ぢ
    2021-02-03 18:33

    I suspect the issue is that you're using queryParams instead of just params.

    params: An Observable that contains the required and optional parameters specific to the route.

    queryParams: An Observable that contains the query parameters available to all routes.

    so try this:

    this.route.params.subscribe(params => {
       console.log(params);
       console.log(+params['id']);
    }); 
    

提交回复
热议问题