Angular $location.path() and window.location.reload not working in Safari/Firefox
Asked Answered
T

3

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.

Teucer answered 17/9, 2015 at 19:4 Comment(3)
why do you want to call location.reload()? Might as well just skip $location.path()Knotted
I would like to force the app to reload and clear state in all of my services.Teucer
so just set url with $window.locationKnotted
T
2

Thanks. The below resolves the issue.

$window.location.href = lastPath;
Teucer answered 17/9, 2015 at 19:18 Comment(0)
P
2

You can do this:

$window.location.href='#/home';
$window.location.reload()
Pals answered 7/11, 2015 at 0:36 Comment(0)
S
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);    // <---
});

});

Salesclerk answered 8/9, 2016 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.