0

I'm using the router that comes with Angular 1.3.8. I've noticed that when a view is loaded and I do a browser refresh, that the controller for that view is not reloaded. I have to go to another view and then back to get it to reload. What is the reason for this and is there a way to get it to reload on a refresh?

Thanks.

Router Code:

    $routeProvider
        .when('/Grid', {
            templateUrl: "Home/Grid",
            controller: "GridExample",
        controllerAs: 'vm'
    })
    .when('/AutoComplete', {
        templateUrl: "Home/AutoComplete",
        controller: "AutoComplete",
        controllerAs: 'vm'
    })
    .when('/WebApi', {
        templateUrl: "Home/WebApi",
        controller: "WebapiGridExample",
        controllerAs: 'vm'
    })
    .otherwise(
            {
                redirectTo: '/home/Index'
            });
Michael Witt
  • 1,582
  • 4
  • 22
  • 43

1 Answers1

1

Is this for all browsers? because IE, Chrome, Safari, Firefox may behave differently. But to address the issue:

You can force a refresh with

$route.reload();

You can just put that at the beginning of your controller and it should work. Also, these would be good things to read:

How to watch for a route change in AngularJS?

AngularJS Paging with $location.path but no ngView reload

Community
  • 1
  • 1
SoluableNonagon
  • 11,541
  • 11
  • 53
  • 98