1

in controller A I do $location.path('/home'), but actually I want a normal redirect. $location.path does not reload the page. I know in ui-route there's $state.go({reload:true}), but how to do it with normal ngRoute? I do

.controller('home', function($route){
$route.reload()
}

I got an infinite loop.

Jamie Anderson
  • 109
  • 1
  • 7

2 Answers2

0

You can use the window object to reload instead of $location.path('/path');:

window.location = '/path';

If you want to use ngRoute, you can reload the page on routeChange:

myApp.run(['$route', '$rootScope', function ($route, $rootScope) {
    return $rootScope.$on('$routeChangeStart', function (event, next, current) {
        $route.reload();
    });
}]);
salix
  • 846
  • 6
  • 13
0

First why you want reload the page while location change in navigation?. I think we don't need reload() on location change.

you are given $route.reload() as on-fly function. The controller execute while navigate and check on-fly function and run $route.reload();. so the route is reload and again the controller initiate, and again execute on-fly function $route.reload();. so the reload is going infinity.

You can try $route.reload in function ng-click as per need. don't use reload() function as on-fly function.

Example.

$scope.saveData = function(){
 //some save functionality and reload the route
$route.reload();
}

<button ng-click="saveData">Save</button>
Manikandan Velayutham
  • 2,228
  • 1
  • 15
  • 22