【问题标题】:How to reload page in angularjs如何在angularjs中重新加载页面
【发布时间】:2016-11-03 17:56:34
【问题描述】:

我需要在 ionic 应用中重新加载页面。

我正在使用{reload:true} 方法,但对我不起作用。

那么有人提出解决这个问题的想法吗?以及如何删除 ionic 中的localstorage item 值?

【问题讨论】:

  • $route.reload(),可能是localStorage.remove('key')
  • 抱歉,缺少代码
  • localstorage.remove(key) 将删除与 key 一起存储的数据

标签: angularjs ionic-framework local-storage


【解决方案1】:

试试:

$window.location.reload(); 

您使用$route.reload() 重新加载路线。

如果您使用的是$stateProvider,请尝试:

$state.go($state.current, {}, {reload: true}); 

【讨论】:

  • 我尝试了所有方法,但它不起作用。给任何建议
【解决方案2】:

我认为您在重新初始化 ionic 控制器时遇到问题。而不是在离子中重新加载您的页面。我更喜欢你使用以下内容:

angular.module('nameYouSPecify').controller('your controllername',function($scope){
  $scope.$on('$ionicView.beforeEnter', function(){ 
//keep all your codes inside here
});

})

如果你真的需要重新加载页面。Ionic 使用$stateProvider。因此,要重新加载,请使用以下内容:

angular.module('nameYouSPecify').controller('your controllername',function($scope,$state){
     $state.go('StateName',{},{reload:true});
    //the middle blank is filled with stateparams if you have any  
});

要删除 localStorage$window.localStorage.clear();.Inject $window in controller。

要删除$localStorage$localStorage.$reset();。您需要ngStorage,并且需要在控制器中注入$localStorage

【讨论】:

    【解决方案3】:

    把它放在你的controller.js中

    $state.go($state.current, $stateParams, {reload: true, inherit: false});
    

    还要确保在 app.js 中将缓存设置为 false

    【讨论】:

      猜你喜欢
      • 2014-03-20
      • 2016-03-13
      • 2015-12-17
      • 2013-09-17
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多