Angular · Junior · Question 59 of 75

How do you read the :id parameter of the current route in a component?

private route = inject(ActivatedRoute);
id = this.route.snapshot.paramMap.get('id');

Explanation

The snapshot is enough if the component is recreated per id. If the same component stays on screen while the id changes, subscribe to paramMap or use input binding.

Further reading

Problem with a question

Angular · Junior · question 59

Test yourself

Take the Angular · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz