why ActivatedRoute
in @angular\router params is observable
?
I'm wondering why do I need to subscribe for Params ? and why params are async is there a case the componenet of the route will be created but the params still not populated ?
and is there a way to just get the value without an observable
?
ActivatedRoutelink. Provides access to information about a route associated with a component that is loaded in an outlet.
Docs (https://angular.io/api/router/Router and https://angular.io/api/router/ActivatedRoute) both say something along the lines of "router does redirecting" and "ActivatedRoute" is the source of info on the route. Router does redirecting, don't call APIs about "getting the route information".
Accessing Query Parameter Values The ActivatedRoute class has a queryParams property that returns an observable of the query parameters that are available in the current URL. There's also queryParamMap , which returns an observable with a paramMap object.
You can use
route.routerState.params
You can subscribe because when your application navigates to the same route with just another parameter value, the component is not recreated and you have no way of knowing when the parameters have changes.
With subscribing to parameters you get notified, that a route action has happened where only the parameter value changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With