Save user object in Session Storage

落爺英雄遲暮 提交于 2019-12-05 03:02:08

Its ok to have secure/sensitive data in session storage.

As session storage only available for current table and domain...

If user check same session storage data in another window tab then it will not be there....so its secure storage....

If want to know more, please have look on sessionStorage

You could either use sessionStorage or use a service.

Your interface:

export interface ISession {
    session:Object
}

Your actual service class:

    import {Injectable} from '@angular/core';

    @Injectable()
    export class SessionService implements ISession {    
        private _session: session

        constructor(){

        }

        set session(value){
            this._session = value;
        }

        get session(){
            return this._session
        }
   }

Now you can inject this SessionService class in other class constructors and use it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!