您的位置:首页 > 其它

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

2016-05-06 17:40 375 查看

有人可能知道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.comhttps://blog.csdn.net/blog/2296403

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐