Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing objects in routing [duplicate]

I have a component in Angular2 hosting the table of users (userTableComponnent) and another component of userDetails. Upon clicking on a row in users table, I want to route to the userDetails. One implementation is to pass the userId only, so in userDetails, I fetch the details of the user with another http get. However, this is redundant, as I grab all the user info in userTableComponent. So what I really need is to pass the User object from userTableComponent to userDetails. Any idea how to achieve it through routing?

like image 257
Hammer Avatar asked May 03 '16 03:05

Hammer


1 Answers

You can create a SessionService class and pass it around your App via Dependency Injection.

Once the user is selected you can attach the relative data to the SessionService instance injected via DI and retrieve it in the userDetails Component.

I hope it helps

like image 102
Picci Avatar answered Oct 23 '22 12:10

Picci