ChangeState 后重置/卸载控制器(注销调用).AngularJS [英] Reset/Unload Controller after ChangeState (logout called) . AngularJS

查看:28
本文介绍了ChangeState 后重置/卸载控制器(注销调用).AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,用户可以在其中从 Facebook 或 Twitter 登录.登录后,用户被定向到某个主页.在这里,控制器加载并调用我的初始函数,该函数加载特定于该用户的数据.

I am Creating an app where the user can login from FaceBook or Twitter. After login, the user is directed to some HomePage. And here, controller loads and my initial function is called which loads data specific to that user.

当用户点击注销时.令牌被清除,用户被定向到登录页面.现在无需关闭应用程序,如果用户再次使用 Twitter 登录,用户将被定向到相同的主页.该控制器的 Scope 具有相同的数据.我知道 Ionic 使用缓存来提高性能.但我只想在用户单击注销按钮时清除该缓存.

When user clicks on Log Out. The tokens are cleared and user is directed to SignIn Page. Now without closing the app, if the user SignIn again using twitter, The user is directed to same homepage. The Scope of that controller has the same data. I know Ionic uses cache to improve performance. but I just want a way to clear that cache only when user clicks on logout button.

推荐答案

我找到了解决方案,我们需要在下一个/其他摘要循环中清除缓存.通过使用 $timeout 我们可以实现这一点.像这样的东西.

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

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

给一些毫秒的时间来清除功能,效果很好.

Give some milliseconds to clear functions at it works great.

这篇关于ChangeState 后重置/卸载控制器(注销调用).AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆