Angular/Ionic Singleton gets destroyed after refresh

i have a singleton typescript class that stores the Login Credentials of a user. I set them on the login Page and go to the next page with my Angular Router.navigate. (without params), on the next page i want to consume my singleton, and it works perfectly, but if Irefresh the page the singleton is undefined?
How can i solve this?

This is the error after refreshing:

  • core.js:5980 ERROR Error: Uncaught (in promise): TypeError: Cannot
    read property ‘socialSecurityNumber’ of undefined TypeError: Cannot
    read property ‘socialSecurityNumber’ of undefined

Thanks

4 thoughts on “Angular/Ionic Singleton gets destroyed after refresh”

  1. If you refresh the page (F5 in the browser) the whole SPA gets bootstrapped again and services created again.

    That means that the new instance of the service will not have the user data unless stored in the storage or cookies.

    Also check that the service is provided "in root" and not in any module providers array, so there are no copies of it.

    Reply

Leave a Comment