最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS – $route.reload() not working - Stack Overflow

programmeradmin3浏览0评论

I'm trying to reload page using $route.reload():

var App = angular.module("App", ["ngRoute"]);  
var idx = 0;  

App.controller("List", function ($scope, $route) {
    $scope.changeWallet = function (index) {
        idx = index;
        $route.reload();
        console.log("success");
    };
}

"success" is shown in console, but nothing happens.
How can I fix this?

I'm trying to reload page using $route.reload():

var App = angular.module("App", ["ngRoute"]);  
var idx = 0;  

App.controller("List", function ($scope, $route) {
    $scope.changeWallet = function (index) {
        idx = index;
        $route.reload();
        console.log("success");
    };
}

"success" is shown in console, but nothing happens.
How can I fix this?

Share Improve this question edited Jun 2, 2014 at 8:37 Prophet 33.4k28 gold badges57 silver badges90 bronze badges asked Jun 2, 2014 at 8:34 supertrallsupertrall 1151 gold badge1 silver badge7 bronze badges 7
  • Are you using ui-router ? – Satyam Koyani Commented Jun 2, 2014 at 8:42
  • So Do you want to refresh template only ? – Satyam Koyani Commented Jun 2, 2014 at 8:44
  • Remove template from cache first then try to reload the template.add this "var currentPageTemplate = $route.current.templateUrl; $templateCache.remove(currentPageTemplate);" before reload function call. – Satyam Koyani Commented Jun 2, 2014 at 8:48
  • I got undefined is not an object (evaluating '$route.current.templateUrl') – supertrall Commented Jun 2, 2014 at 8:56
  • I don't believe it is anything to do with template cache. @supertrall You you want to reload the view partial or the plete page? – Chandermani Commented Jun 2, 2014 at 8:57
 |  Show 2 more ments

2 Answers 2

Reset to default 10

If you want to reload the plete page instead of route refresh inject the $window service and call location.refresh

$window.location.reload();

The $window.location.reload() will basically refresh the page like when you're pressing F5 for refresh.

What I am after is reload the specific views in the page not refreshing the entire page.

发布评论

评论列表(0)

  1. 暂无评论