1

In login page i am saving one value in array ,after login in home page i need to use that,but it showing undefined ,and when i refresh the page its fine. The login page code that i used is,

 this.userRoles.push({"id":1,"name":test});
            
 sessionStorage.setItem('roles',JSON.stringify(this.userRoles));

When i inspect the sessionStorage it showing, the home page code that i used to retrieve the session value is,

  this.roles = JSON.parse(sessionStorage.getItem('roles'));

but it showing undefined

NJKannur
  • 91
  • 2
  • 4
  • 13
  • https://stackoverflow.com/questions/60750915/saving-data-in-sessionstorage-as-undefined-in-angular –  Sep 09 '20 at 03:55
  • use BrowserStorageService that is explained in this link, It will work perfectly https://stackoverflow.com/questions/40589730/local-storage-in-angular-2/57635667#57635667 – Abolfazl Roshanzamir Sep 09 '20 at 05:59
  • please explain at what event you are setting values and at what even you are getting values. the guess here is that your get is executing even before it was set in session storage. – Aakash Garg Sep 09 '20 at 06:01
  • i use both option but , same only get value after refresh – NJKannur Sep 10 '20 at 02:33

0 Answers0