简体   繁体   中英

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.

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?

我强烈建议你实现一些服务器端框架并实现数据库并以这种方式存储和检索数据,它更清洁,更可靠,会话是一种非常过时的做事方式,至少我会使用cookie,所以他们在至少坚持得更可靠一点。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM