1

I know this question is possibly duplicate however I didn't understand their answers, so I am asking it.

I have a search page and a view page for Customer Details. In search page if I enter name then I get list of matching customer names.

Now I want to create a link or a button that if I click on it then I should be able to view all the details of that customer such as customer History and everything. I have both the Search and View Page ready.

My question is how do I create a navigation that if I click on a particular user it will take me to View page and display all the Information related to that Customer

Ashishkumar Singh
  • 3,580
  • 1
  • 23
  • 41
Cpt Kitkat
  • 1,392
  • 4
  • 31
  • 50
  • You need to look into Routing, RouteParameters, and Services. – moritzg Mar 28 '19 at 13:07
  • @moritzg are these three different ways to do it or ...? – Cpt Kitkat Mar 28 '19 at 13:09
  • There multiple ways to do it but I would use the Router to go to the next page, use parameters in your URL to give the Details page your ID and then retrieve the details with the ID using a service. – moritzg Mar 28 '19 at 13:11
  • What i can't understand is that how will i get the data. I mean in view screen right now i hit an api with customer id and then display the info.But how will I pass the value of customer id in api that is on different page – Cpt Kitkat Mar 28 '19 at 13:12
  • Why not use the api in the details view as well? – moritzg Mar 28 '19 at 13:15
  • Found my solution on this link https://stackoverflow.com/questions/39325503/how-to-pass-data-between-two-components-in-angular-2. Answered by Abhijit Srivastava. His answer is super easy – Cpt Kitkat Mar 28 '19 at 14:09
  • I wouldn't use `sessionStorage` though; I mean, Angular has ways to handle this so you keep everything synced; – IvanS95 Mar 28 '19 at 14:19

2 Answers2

0

Some time ago, I blogged on how to pass data using the router: https://yakovfain.com/2015/11/11/angular-2-passing-data-to-routes/

The use case that you're trying to implement looks to me like a master-detail view (list of customers is "master" and the customer details view is "detail"). I wrote another blog on this particular scenario: https://yakovfain.com/2016/11/20/angular-2-implementing-master-detail-using-router/

Yakov Fain
  • 11,972
  • 5
  • 33
  • 38
0

You could use a localstorage to solve it. It's so easy to do and works like a BD Key->Value on front-end.

Leandro Castro
  • 241
  • 2
  • 13