This is how I handle my routing in Angular. I have a couple of files where all the needed data about each route is stored and I iterate over the data like this. .html requests are for loading templates and .action for AJAX requests.
What I need to do is treat all the cases where the server doesn't succeed (300, 400, 500 etc). I googled all I thought relevant found some info about it but nothing seems relevant or clear enough. How exactly do I access the header data of a request?
Application.config(['$routeProvider', '$interpolateProvider', '$httpProvider',
function($routeProvider, $interpolateProvider, $httpProvider)
{
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
for (var i=0; i < applicationRoutes.length; i++) {
if (applicationRoutes[i].hasInitialData)
{
$routeProvider.when('/' + applicationRoutes[i].path + '.html', {
templateUrl: applicationRoutes[i].path + '.html',
controller: applicationRoutes[i].controller + ' as ' + applicationRoutes[i].controllerAlias,
resolve: {
initData : ['Initialize', '$route', function(Initialize, $route)
{
//console.log($route.current.$$route);
return Initialize.serverData('/' + $route.current.$$route.pathBase);
}]
},
pathBase: applicationRoutes[i].path
}).otherwise('/404');
}
else
{
$routeProvider.when('/' + applicationRoutes[i].path + '.html', {
templateUrl: applicationRoutes[i].path + '.html',
controller: applicationRoutes[i].controller + ' as ' + applicationRoutes[i].controllerAlias,
pathBase: applicationRoutes[i].path
}).otherwise('/404');
}
}
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
}
]);