Resolve is an interesting property to prevent a template to be displayed regarding some conditional logic dealing with a promise result (solved or rejected).
I use it in my application, here's a conceptual sample:
.config(['$routeProvider', 'securityAuthorizationProvider',
function ($routeProvider, securityAuthorizationProvider) {
$routeProvider.when('/test', {
templateUrl: '/myCorrespondingView.tpl.html',
controller: 'MyCorrespondingCtrl',
resolve: securityAuthorizationProvider.requireAuthenticatedUser
});
}])
So, this code expects to display /myCorrespondingView.tpl.html
content if and only if securityAuthorizationProvider.requireAuthenticatedUser
is resolved (promise term).
My expectation is: I don't want to change the URL to http://myApp.com/test
if this promise in resolve
part is rejected. The reason is simple, I don't want to uselessly reload the previous controller if my rejection logic is to let the user on his current page (thus needing a redirection to this latter) .
Is there an efficient way to achieve this with the resolve
property other than shifting the conditional logic at the source, meaning into the previous controller?