Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why ActivatedRoute in @angular\router params is observable?

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 ?

like image 371
Mina W Alphonce Avatar asked Nov 13 '16 18:11

Mina W Alphonce


People also ask

What does ActivatedRoute do in Angular?

ActivatedRoutelink. Provides access to information about a route associated with a component that is loaded in an outlet.

What is the difference between ActivatedRoute and router?

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".

Which property of ActivatedRoute class helps read query parameter values?

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.


1 Answers

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.

like image 159
Günter Zöchbauer Avatar answered Oct 21 '22 09:10

Günter Zöchbauer