首页 > 解决方案 > 关闭浏览器后如何恢复angular 6应用界面状态

问题描述

我们目前是一个使用 Angular 6 开发单页应用程序的团队。

此应用程序有一个“主页”页面,其中包含一个导航栏,我们可以从中访问应用程序功能。

在主页中动态创建的窗口“ primeng dialog ”中表示的每个功能。

所以我们要做的是,当用户在注销或关闭浏览器后重新连接时,他可以将主页恢复为上次连接时的状态“之前打开的窗口将自动重新打开”。

我们的目的是创建一个可以保存她的状态的应用程序,就像保存您的工作站的许多其他应用程序一样。

标签: angularangular5angular6

解决方案


Like the first comment said, you will probably want to save that status in local storage. Anyone that has access to the computer has access to the local storage, so it is best to not put sensitive information in there. We typically try to only use database row id's and enums in local storrage.

ngOnInit() {
   this.userStatus = localStorage.getItem('currentStatus');
}

someFunctionThatIsUsedToChangeStatus() {
    // logic to change status
    // ...

    localStorage.setItem('currentStatus', this.userStatus);
}

推荐阅读