2

I have two html pages. First page being a list of patients each being a hyperlink. The expected behavior is that, on click of a hyperlink ( corresponding to a patient), the user should be redirected to another html page which has the details of the corresponding patient. The redirection is happening. But, I am not able to pass the data from the first html page to the second one.

6
  • Post some code. Are you using 2 controllers and 2 templates, 1 controller and 2 templates, do you have a directive setup for displaying the data? Too many questions to give an answer. Commented Mar 30, 2016 at 11:26
  • Possible duplicate of Angularjs: build url with query string Commented Mar 30, 2016 at 11:31
  • U need to pass object or string to another page ? Commented Mar 30, 2016 at 11:34
  • I have two Controllers. Using Controller1, I'm able to display the list of patients(by performing a get operation). Each link(link being a patient) has a unique patient id. I have a function such that on click of the link, it sends the patiend id to the controller(Controller1). Making use of $broadcast and $on , I'm able to send that patient id to Controller2. I'm even able to display the Patient id selected(clicked) from Controller2. BUT I can do this only in page1.html(i.e. below the list of patients, without directing to page2.html). But what I ideally want is to send the pat id to page2. Commented Mar 30, 2016 at 11:38
  • Possible duplicate of Angularjs pass data in between services that exist on different pages Commented Apr 1, 2016 at 9:21

2 Answers 2

2

There are plenty of way to do that:

  1. localStorage of the browser (angular plugin)
  2. URL parameters (angular $location)
  3. Server-side session
  4. Cookies, outdated and inefficient nowadays, better go for #1 (using cookies with angular)

Best applicable implementation depends on your architecture on front/back

Sign up to request clarification or add additional context in comments.

Comments

1

The URL should contain an ID for the item you want to display, e.g. /patient/432.

Using that ID, the second page loads the data.

If you are using Angular, and both pages are in fact part of a single app, you would use a Service that caches the data. That is, the service loads your patients list and returns either a list or a single item from the list. That way, you don't have to load the individual items from the server API each time.

3 Comments

Thank You C14L, I used a service to share the data between two pages. But the problem now is I'm not able to share a data which is inside a function of controller1 to Controller2. If you could help me out with this?
Does the controller1 change the data? It should call a method on your service to do that. And that method changes the data in the service, that is then accessible to all controllers. Alternatively, you could store the data as a property on $rootScope and change it there, then your controller2 could access to too.
No Controller1 doesn't change the data. It just picks up the argument(i.e.Pat Id), and I'm kinda lost with $rootScope example which you have mentioned. Could You please elaborate it? Thanks in Advance:)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.