Reset / Unload the controller after ChangeState (login is called). Angularjs

I am creating an application in which a user can log in to FaceBook or Twitter. After logging in, the user is redirected to the home page. And here the controllers load, and my initial function is called, which loads the data specific to this user.

When the user clicks the "Logout" button. Tokens are cleared and the user is directed to the login page. Now, without closing the application, if the SignIn user uses Twitter again, the user is redirected to the same home page. The volume of this controller has the same data. I know that Ionic uses cache to improve performance. but I just want to clear this cache only when the user presses the exit button.

+2
source share
2 answers

I found a solution, we need to clear the cache in the next / other digest cycle. Using $timeout , we can achieve this. Something like that.

 $scope.logout = function(){ $location.path('/signin') $timeout(function () { $ionicHistory.clearCache(); $ionicHistory.clearHistory(); $log.debug('clearing cache') },300) } 

Edit: give a few milliseconds to clear functions on it, works great.

+6
source

You can handle this by calling the $ionicHistory.clearCache() method to clear the old caches. You can also call $ionicHistory.clearHistory() to reset the story so that it is like a new session.

http://ionicframework.com/docs/api/service/ $ ionicHistory /

+1
source

Source: https://habr.com/ru/post/985035/


All Articles