45

What are the different paramMap and queryParamMap?

Angular website says paramMap - An Observable that contains a map of the required and optional parameters specific to the route. The map supports retrieving single and multiple values from the same parameter.

queryParamMap - An Observable that contains a map of the query parameters available to all routes. The map supports retrieving single and multiple values from the query parameter.

I would like to know when I have to use with examples.

Thanks

Su Park
  • 463
  • 1
  • 4
  • 6

2 Answers2

55

ParamMap for routes like user/:id. Id param belongs only this route.

QueryParamMap is for eg. user/:id?tab=edit. Tab is a global query param, it can be read from the ActivatedRoute in the user route's component as well as any of its ancestors.

funkizer
  • 4,626
  • 1
  • 18
  • 20
6

params—An Observable that contains the required and optional parameters specific to the route. Use paramMap instead.

queryParams—An Observable that contains the query parameters available to all routes. Use queryParamMap instead.

DV Singh
  • 1,038
  • 11
  • 16