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.
Asked
Active
Viewed 1.0k times
3
-
use local storage instead of cookies. You will have lot of advantages over cookies. – aditya May 25 '17 at 00:39
2 Answers
4
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.
- LocalStorage
- Cookie
- Session
Difference and importance: How to store token in Local or Session Storage in Angular 2?
-
I would like to go with LocalStorage for various reasons. – Talk is Cheap Show me Code Mar 08 '18 at 12:03
2
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.

Trevor Hart
- 993
- 7
- 26