Best practices for Clearing data in services on logout in AngularJs

后端 未结 2 1255
时光取名叫无心
时光取名叫无心 2020-12-31 06:21

I have several services which uses a webservice and caches a lot of the results.By caching i mean storing in a variable on the service. When a user logs out the data should

相关标签:
2条回答
  • 2020-12-31 06:54

    you can use a full page refresh:

    $window.location.reload();
    

    this will restart the whole state of your application

    another solution could be to store everything in session storage and then clear it on log out:

    sessionStorage.clear();
    
    0 讨论(0)
  • 2020-12-31 07:00

    You can create a service which is responsible clearing all the the data from the other services. In this case you only have to call the "clear" method of this service, and implement the individual clear calls inside of this one (so only implemented once).

    This gives you also the advantage that you have an overview of which services data need to be cleared all the time, since you might have exceptions in the future.

    Also see this answer for your reference: Injecting a service into another service in angularJS

    0 讨论(0)
提交回复
热议问题