0
votes

I'm desperately trying to get the route params from a service so when I access a section from the url, I can detect the section's id and load it in this service.

The route path is 'sections/:section' with children. This gives a URL like this: /sections/2/home

I tried to use the following:

this.route.paramMap.subscribe(params => {params.get('section');});

But it returns "null"...

I also tried other options but it returned an empty string :/

Any ideas? Thanks for your time!

1
Can you show some code. Where you are calling it and how you are navigatingyazantahhan
Sorry about that, I'm out of the office so I can't post the whole thing... I'm trying to subscribe when the service is instantiated in constructor() { this.route.paramMap.subscribe(params => {params.get("section");}); }Romain Mascia
here is an example i created on router params : stackblitz.com/edit/angular-vcab7eCruelEngine
So, from a component I managed to get it. But not from a service :/Romain Mascia
Because the ActivatedRoute object is heirarchical, it is tough to get what you are looking for from a service. If you look at your this.route, you will notice that it has children routes. What you are looking for is buried in the children routes somewhere. You have to look through that tree to find it. It is confusing and really drives me crazy. Sorry you are being frustrated by this. It frustrates a lot of people, FYI.frosty

1 Answers

0
votes

Specify the router path as, {path: 'resetpassword/:token', component: ForgotPasswordComponent}

  constructor(private route: ActivatedRoute) { }
  this.route.params.subscribe(params => {
    this.userdetails=params.token;
  });
}