Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retain data on page reload in Angular 2

In my Angular 2 app, I pass in some data to a PageComponent from my HomeComponent which is then saved to a variable inside the PageComponent. Now when I refresh the page I need this data to be retained. Currently I am using session storage, but I was wondering if there is a better way to implement this.

like image 491
Vinaayakh Avatar asked Jan 18 '26 02:01

Vinaayakh


2 Answers

Nope, There isn't a other way in this context. Once you refresh all the temporary memory is gone. As you said you are performing session-storage. You may continue with that. You may choose the below.

  1. LocalStorage
  2. Cookie
  3. Session

Difference and importance: How to store token in Local or Session Storage in Angular 2?

like image 166
Smit Avatar answered Jan 20 '26 17:01

Smit


I would strongly advise you implement some server side framework and implement a database and store and retrieve data that way, it's a lot cleaner and much more reliable, session is a very dated way of doing things, at minimum I would use cookies so they at least persist a little more reliably.

like image 40
Trevor Hart Avatar answered Jan 20 '26 18:01

Trevor Hart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!