3

I am trying to reload a route from my controller using $route.reload() but nothing is happening. Here's my controller:

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

I'm using angular-route-segment for my routes and the associated route looks like this:

 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"
      }
    });
  });
Charlie
  • 10,227
  • 10
  • 51
  • 92

1 Answers1

1

Inject $routeSegment instead of $route.

The property chain is an array of segments splitted by each level separately and each element will have a reload method.

For example:

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

Other properties and methods available on $routeSegment and the elements in the chain array can be found here.

tasseKATT
  • 38,470
  • 8
  • 84
  • 65
  • Thanks I'd ended up doing this, but reloading the last in the chain array like this: $routeSegment.chain[$routeSegment.chain.length - 1].reload() – Charlie Dec 08 '14 at 20:02