I'd like to use the resolve function to delay loading of a ng-view until I've retrieved data from the server. However, I'd like to display the view once the $http response is returned even if there is an error (for example, when the server sends a 401 or 500 header). Angular seems to assume we don't want to show the view in this case and broadcasts a $routeChangeError and logs an exception to the console. Is there a way to avoid that behavior? This seems to happen only in resolve, because it works if I put the $http code in MyCtrl.
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'template.html',
controller : MyCtrl,
resolve : MyCtrl.resolve
});
});
function MyCtrl($scope, data) {
$scope.data = data;
}
MyCtrl.resolve = {
response : function($http) {
success(function(data, status) {
// This works and data is injected into MyCtrl
return data;
})
.error(function(data, status) {
// This doesn't work. Angular broadcasts $routeChangeError and logs an exception to the console
return 'error';
});
}
}