【问题标题】:Angular $location.path() and window.location.reload not working in Safari/FirefoxAngular $location.path() 和 window.location.reload 在 Safari/Firefox 中不起作用
【发布时间】:2015-09-17 19:04:59
【问题描述】:

由于某些原因,这适用于 IE 和 Chrome,但不适用于 Safari 和 firefox。

$location.path(lastPath);
$window.location.reload(true);

不是重新加载最后一个路径,而是重新加载当前页面$window.location.reload(true)。在 Chrome 和 IE 中,重新加载发生在 angular 的 $location.path(lastPath) 发生之后。

【问题讨论】:

  • 为什么要打电话给location.reload()?还不如跳过$location.path()
  • 我想强制应用重新加载并清除我所有服务中的状态。
  • 所以只需用$window.location设置网址

标签: angularjs window.location


【解决方案1】:

谢谢。下面解决了这个问题。

$window.location.href = lastPath;

【讨论】:

    【解决方案2】:

    你可以这样做:

    $window.location.href='#/home';
    $window.location.reload()
    

    【讨论】:

      【解决方案3】:

      我正在使用 angular 1.5.6 的科尔多瓦进行开发。简单的动作:

      $location.path("/someurl");
      $window.location.reload();
      

      适用于 chrome 和 android 应用程序,但不适用于 ios 应用程序。适用于所有平台的方法是在位置路径更改后重新加载。

      这是使用$locationChangeSuccess 事件实现的。给出的是一个完整的控制器代码,这样事情就很清楚了。 $location.path 被标记,$window.location.reload() 被放置在 $locationChangeSuccess 处理程序中。

      angular.module("demo").controller("LoginCtrl", function($scope, $http, $location, $window) {
      
      $scope.dologin = function() {
          $scope.message = "";
          $http.post(app.baseurl + "/app/login", {
            email: $scope.email,
            password: $scope.password
          }, 
          {
            withCredentials: true
          }).success(function(response){
            $location.path("/dashboard"); // <---          
          }).error(function(response) {
            $scope.message = "invalid user/pass: ";
          });
      }
      
      $scope.$on('$locationChangeSuccess', function() {
        $window.location.reload(true);    // <---
      });
      

      });

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多