简体   繁体   中英

How can I save state of component in Angular?

I'm looking at saving the state of a data table that I'm using in Angular 7 & Typescript.

The functionality is similar to saving state like in a browser tab.

So on redirection to another component, If I go back to the component with the data table, how can I save the state let's say if I'm using a filter?

尝试使用像https://ngrx.io/guide/store这样的状态管理库或使用 localstorage 来保存和获取过滤器。

1 method would be to store the state in the local storage. So when you return back to the original page you can query to see if the item exists in the local storage if it does then reinitialise.

let data = {}; localStorage.setItem('settings', data);

this is not an effective way just for learning purpose its fine

  1. Local storage
  2. ngrx/Store
  3. Subject, or BehaviorSubject

The last option is two directional service, the best option would be probably Store.

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