0

What is preferred way to share data (Object) between controllers with different routes and prevent data lost after reloading?
I need this object to prefill form values in my destination page which depends on choices in my source page.

Solutions I got so far are:
1- to send serialized Objects as query string parameter.
2- or using local storage and give special parameter to url so it knows when to fetch from local storage and when to open empty form.

Solutions which I can't use:
1- Shared service as my data would be lost after reload in this case.

Is there any other way, if not which way is more preferred?
note: there has to be no lost data after reloading page.

Basel Issmail
  • 3,847
  • 7
  • 20
  • 36
  • Possible duplicate of [Share data between AngularJS controllers](https://stackoverflow.com/questions/21919962/share-data-between-angularjs-controllers) – ruby_newbie Mar 01 '19 at 23:00
  • 1
    @ruby_newbie, My question is different as it has to meet the condition of not losing data after reloading page. this case is not common as it is SPA, but I need a solution for this case. – Basel Issmail Mar 02 '19 at 00:29
  • 2
    If you need it after reloading the page your only choices are to store it in a session on the server, a cookie, or localStorage. After that it's just a matter of pulling the data out of one of those places on reload and "hydrating" your app with it. – Adam Jenkins Mar 02 '19 at 00:35
  • @BaselIssmail did my answer worked ? – Shashank Vivek Mar 12 '19 at 05:01

1 Answers1

1

IMHO , there could be only 2 ways to handle this:

  1. Using localStorage or sessionStorage

  2. You use session management from server side keep the session consistent.

If it's just about retaining the data after page reload for a route, just go for sessionStorage. But it depends on the use case of your project.

Shashank Vivek
  • 16,888
  • 8
  • 62
  • 104