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.

Ayush
  • 33
  • 1
  • 4
  • 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. – mikeb Mar 30 '16 at 11:26
  • Possible duplicate of [Angularjs: build url with query string](http://stackoverflow.com/questions/18665850/angularjs-build-url-with-query-string) – Bonatti Mar 30 '16 at 11:31
  • U need to pass object or string to another page ? – rejo Mar 30 '16 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. – Ayush Mar 30 '16 at 11:38
  • Possible duplicate of [Angularjs pass data in between services that exist on different pages](http://stackoverflow.com/questions/19727131/angularjs-pass-data-in-between-services-that-exist-on-different-pages) – catzilla Apr 01 '16 at 09:21
  • you should try using post or get methods on the form in your backend.. – catzilla Apr 01 '16 at 09:24

2 Answers2

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

shershen
  • 9,875
  • 11
  • 39
  • 60
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.

C14L
  • 12,153
  • 4
  • 39
  • 52
  • 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? – Ayush Mar 31 '16 at 11:41
  • 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. – C14L Mar 31 '16 at 13:04
  • 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:) – Ayush Apr 01 '16 at 08:53