Я реализую аутентификацию на основе токена с помощью AngularJS. Маркер создается на сервере и возвращается клиенту. После аутентификации токен будет добавлен в заголовок каждого остального вызова. Я создал authInterceptor:AngularJS: ошибка ввода http-перехватчика
ristoreApp.factory('authInterceptor', function ($rootScope, $q, $window) {
return {
request: function (config) {
config.headers = config.headers || {};
if ($window.localStorage.getItem("access_token")) {
config.headers.Authorization = 'Bearer ' + $window.localStorage.getItem("access_token");
}
return config;
},
response: function (response) {
if (response.status === 401) {
// handle the case where the user is not authenticated
}
return response || $q.when(response);
}
};
});
Затем вводят его в моих config.js следующим образом:
ristoreApp
.config(function ($httpProvider, authInterceptor, $routeProvider) {
$httpProvider.interceptors.push('authInterceptor');
$routeProvider
.......
})
Однако я получил следующее сообщение об ошибке:
Failed to instantiate module ristoreApp due to: Unknown provider: authInterceptor
Что случилось с моим способом вводить перехватчик?
Можете ли вы разместить свой код детали? Будет лучше, если вы добавите скрипту/plnkr. –