I have incredibly meaningful and powerful error messages that my server passes to the browser if there was any kind of error. But how do I access that info in the following:
$rootScope.$on("$routeChangeError", function (event, current, previous, rejection) {
console.log(rejection); // "An unknown error has occurred."
});
I'm using $routeProvides.resolve in my route definitions, and so $routeChangeError was going to be my way of handling if those promises didn't resolve. Is there for a way for me to access the response from the server and display that somehow?
Thanks!
You dont need to do this in this way, you can do this in your Controller:
In some service:
Each property on a resolve object should be a function that returns a promise. So if one of your routes doesn't resolve, throwing a reason in the
.catch
handler will pass your error information to the $routeChangeError handlerAssuming the data parameter has the data from the server you want to use, this will end up in the rejection parameter on the $routeChangeError event.