Access route params in resolve function
The $routeParams don't seem to be populated when the resolve step is being performed. So, inside my resolve function, I can't access these route params. It seems to me the natural use case for the resolve function would be using the route params to resolve/load something? Am I thinking about this wrong?
My scenario: I have a page with an ID in the URL, I want to grab a resource off the server based on that ID before loading the page. So I'm doing this:
$routeSegmentProvider.when('/accept-invite/:token', 'accept-invite')
.segment('accept-invite', {
templateUrl: 'partials/signin/accept-invite.tpl.html',
controller: 'AcceptInviteCtrl',
resolve: {
invite: function(Auth, $routeSegment) {
return Auth.getInvite($routeSegment.$routeParams.token);
}
}
});
Auth.getInvite() returns an $http.post() promise.
Yes, $routeSegment.$routeParams is populated only when the segment is switched, it is the very meaning of it -- to preserve the state of $routeParams of the currently active segment, not the one which is being activated. While resolving, you might need to use the original $routeParams instead of $routeSegment.$routeParams:
resolve: {
invite: function(Auth, $routeParams) {
return Auth.getInvite($routeParams.token);
}
}
Unfortunately, it doesn't seem as if $routeParams is populated when the resolve functions are called. Seems like a huge loss to not have this functionality.