Avatar ·

How to get query params from URL in Angular 2+?

Hi everyone! I just started learning Angular (version 2, I think, or 4, now I'm writing on version 17, but the essence is the same). I encountered a seemingly simple task: I need to read parameters from the browser URL string. I have a page with a list of products, and I want the user to be able to filter them via query parameters. For example, the URL looks like this: `/products?category=electronics&sort=price`. I tried to get these parameters inside the component, but nothing works. I tried using `ActivatedRoute`, but it returns an empty object or `undefined`. Here is my component code (simplified): ```typescript import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-products', template: '

Product list

'