tezvyn:

Angular: Reading URL Query Parameters

Source: angular.devintermediate

Angular gives you two ways to read URL query params: a static `snapshot` for the initial value, or a `queryParams` Observable for live updates. Use it for values like `?search=term`.

Angular's `ActivatedRoute` offers two ways to read URL query params like `?sort=asc`. You can grab a one-time `snapshot` of the params when the component loads, or subscribe to the `queryParams` Observable to get a live stream of changes. This is crucial for filtering data from the URL. The biggest footgun is using the `snapshot` in a component that the router might reuse; if the URL changes but the component doesn't re-render, the snapshot will be stale and your component will show outdated information.

Read the original → angular.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Angular: Reading URL Query Parameters · Tezvyn