Retain data on page reload in Angular 2

Vinaayakh picture Vinaayakh · Mar 7, 2017 · Viewed 9.5k times · Source

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.

Answer

Smit picture Smit · Mar 7, 2017

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?