复位/卸载控制器后改变状态(称为注销)。 AngularJS [英] Reset/Unload Controller after ChangeState (logout called) . AngularJS

查看:170
本文介绍了复位/卸载控制器后改变状态(称为注销)。 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,用户被定向到同一个网页。该控制器的范围具有相同的数据。我知道离子使用高速缓存提高性能。但我只是想,只有当用户点击注销按钮的方式来清除缓存。

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.

推荐答案

我找到了一个解决方案,我们需要清除高速缓存中下一个/其他消化周期。通过使用 $超时我们可以做到这一点。事情是这样的。

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.

这篇关于复位/卸载控制器后改变状态(称为注销)。 AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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