I have the following factory definition in my angularjs spa:
(function () {
'use strict';
angular.module('snApp')
.factory('Auth', ['$http', 'localStorageService', function ($http, localStorageService) {
//code goes here
}]);
})();
and then in my config for my app, i have the following http interceptor setup:
var app = angular.module('snApp', ['ui.router', 'LocalStorageModule', ])
.config(['$logProvider', '$stateProvider', '$urlRouterProvider', '$httpProvider', '$provide', function ($logProvider, $stateProvider, $urlRouterProvider, $httpProvider, $provide) {
// Intercept http calls.
$provide.factory('RequestHttpInterceptor', function ($q, Auth) {
return {
// On request success
request: function ($config) {
if (Auth.user) {
$config.headers['XToken'] = Auth.user.token;
}
return $config;
}
};
});
// Add the interceptor to the $httpProvider.
$httpProvider.interceptors.push('RequestHttpInterceptor');
}]);
When I run the app, I get the following error:
Uncaught Error: [$injector:cdep]
I think it has something to do with the $http in my Auth, because if I remove that then it works, but I need it!
If someone can help me understand what im doing wrong, that would be fantastic!