`
是我不够爱
  • 浏览: 11929 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

ionic 用户注销登录时,清空所有页面缓存

阅读更多

有人可能知道ionic的$ionicHistory是有一个清空缓存的命令的,命令如下:

 

clearHistory()

Clears out the app’s entire history, except for the current view.

   

但是此命令然并卵,所以我又看了一下API和源码发现了如下方法:

  

clearCache()

Removes all cached views within every ionNavView. This both removes the view element from the DOM, and destroy it’s scope.

  • Returns: promise

 

 /**
     * @ngdoc method
     * @name $ionicHistory#clearCache
	 * @return promise
     * @description Removes all cached views within every {@link ionic.directive:ionNavView}.
     * This both removes the view element from the DOM, and destroy it's scope.
     */
    clearCache: function(stateIds) {
      return $timeout(function() {
        $ionicNavViewDelegate._instances.forEach(function(instance) {
          instance.clearCache(stateIds);
        });
      });
    },

 

API地址:http://ionicframework.com/docs/api/service/$ionicHistory/

源码地址:https://github.com/driftyco/ionic/blob/master/js/angular/service/history.js#L1

 

然后写了如下代码去清空页面缓存:

 

var views = $ionicHistory.viewHistory().views;
var stateIds = [];
for(var id in views){
      stateIds.push(views[id].stateId);
}
$ionicHistory.clearCache(stateIds).then(function(){
      $location.path('/login');//设置路由地址
})

  

转帖时请注明地址:http://346454763.iteye.com/blog/2296403

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics