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');- ✓Correct answer: Inject
ActivatedRouteand read itsparamMap(or bind it to an input) - 2Parse
document.URLmanually - 3Call
Router.getParam('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.