【问题标题】:Angular $route.reload() not reloading controllerAngular $route.reload() 不重新加载控制器
【发布时间】:2015-02-06 10:59:09
【问题描述】:

我正在尝试使用 $route.reload() 从我的控制器重新加载路由,但没有任何反应。这是我的控制器:

 app.controller("FooController", function($scope, data, $route) {
    $scope.model = data.model;
    $scope.meta = data.meta;
    $scope.reload = function() {
      return $route.reload();
    };
  });

我的路线使用angular-route-segment,相关路线如下所示:

 app.config(function($routeSegmentProvider) {
    $routeSegmentProvider.segment("foo", {
      templateUrl: templatesRoot + "/tickers/oldest.html",
      controller: "FooController",
      resolve: {
        data: function($http) {
          return $http.get("/api/foos").then(function(response) {
            return {
              model: response.data.foos,
              meta: response.data.meta
            };
          });
        }
      },
      untilResolved: {
        templateUrl: templatesRoot + "/loading.html"
      }
    });
  });

【问题讨论】:

    标签: javascript angularjs angular-route-segment


    【解决方案1】:

    注入$routeSegment 而不是$route

    chain 属性是一个由每个级别分别分割的段数组,每个元素都有一个reload 方法。

    例如:

    $scope.reload = function() {
      $routeSegment.chain[0].reload();
    };
    

    $routeSegment 上可用的其他属性和方法以及chain 数组中的元素可以在here 中找到。

    【讨论】:

    • 谢谢我最终这样做了,但是像这样重新加载链数组中的最后一个: $routeSegment.chain[$routeSegment.chain.length - 1].reload()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多