I want to watch local storage but I am unable to write code
my scenario is when user is logged in I am getting user role id and permission list, depeds on permission only side menu is buit ,after login user can switch role, in that case side menu will change accordig to the permission, Here I save role id val in localstorage, when user is switching role role id is changing and permission also changed,
My doubt is how to watch this changes,
I followed this link How can I watch for changes to localStorage in Angular2?
But I am unable to write my scenario, Please help me
My code for reference
constructor(public http: Http,public MenuService:MenuService) {
this.userroleId = localStorage.getItem("roleId")
}
getSideMenu () {
if( this.userroleId == 1) {
this.MenuService.getAdminMenu().subscribe(menuItems => this.menuItems= menuItems, error => console.log(error));
}
if(this.userroleId == 2){
this.MenuService.getpractitionerMenu().subscribe(menuItems => this.menuItems= menuItems, error => console.log(error));
console.log('ss')
}