8

For some reason this works in IE and Chrome but not Safari and firefox.

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

Instead of reloading the last path, $window.location.reload(true) the current page is reloaded. Where as in Chrome an IE the reload occurs after angular's $location.path(lastPath) occur.

Mike Lunn
  • 2,310
  • 3
  • 21
  • 24

3 Answers3

2

Thanks. The below resolves the issue.

$window.location.href = lastPath;
Mike Lunn
  • 2,310
  • 3
  • 21
  • 24
2

You can do this:

$window.location.href='#/home';
$window.location.reload()
cryptic_star
  • 1,863
  • 3
  • 26
  • 47
Jason
  • 21
  • 1
2

I am developing with cordova with angular 1.5.6. The simple action of:

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

works in chrome and the android app, but not the ios app. What works across all platforms is doing the reload after the location path has changed.

This is achieved using the $locationChangeSuccess event. Given is a complete controller code so that things are clear. The $location.path is marked, and the $window.location.reload() is placed in the $locationChangeSuccess handler.

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);    // <---
});

});

Kinjal Dixit
  • 7,777
  • 2
  • 59
  • 68