AngularJs: Reload page

前端 未结 13 2153
孤城傲影
孤城傲影 2020-11-28 19:28
PORTAL_NAME

I want to reload the page. How can I do this?

13条回答
  •  执笔经年
    2020-11-28 20:08

    You can use the reload method of the $route service. Inject $route in your controller and then create a method reloadRoute on your $scope.

    $scope.reloadRoute = function() {
       $route.reload();
    }
    

    Then you can use it on the link like this:

    PORTAL_NAME
    

    This method will cause the current route to reload. If you however want to perform a full refresh, you could inject $window and use that:

    $scope.reloadRoute = function() {
       $window.location.reload();
    }
    


    Later edit (ui-router):

    As mentioned by JamesEddyEdwards and Dunc in their answers, if you are using angular-ui/ui-router you can use the following method to reload the current state / route. Just inject $state instead of $route and then you have:

    $scope.reloadRoute = function() {
        $state.reload();
    };
    

提交回复
热议问题