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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值