Я пытаюсь добавить перехватчик $ http, чтобы я мог добавить заголовок авторизации, но когда я его добавляю, вся маршрутизация перестает работать, но никаких ошибок не выдается.
app.service('APIInterceptor', ['userService', function (userService) {
this.request = function (config) {
var currentUser = userService.getCurrentUser();
if (currentUser) {
config.headers['Authorization'] = "Bearer " + currentUser.access_token;
}
return config;
}
}]);
app.config(['$routeProvider', '$locationProvider', '$httpProvider', function ($routeProvider, $locationProvider, $httpProvider) {
$routeProvider
.when("/login", {
templateUrl: 'Views/login.html?' + $.now(),
controller: 'loginController',
controllerAs: 'vm'
})
.when("/", {
templateUrl: 'Views/home.html?' + $.now(),
controller: 'homeController',
controllerAs: 'vm'
});
// when I comment out the below the routing works
// with this line in all routing stops working
$httpProvider.interceptors.push('APIInterceptor');
}]);