I'm having the problem of circular http dependency in the angular.
I've seen other questions with similar subject matter, but the ways I've tried have not been able to resolve the problem yet.
My Code:
var app = angular.module("app", [ "ngRoute", "ngResource", "toastr", "ngStorage" ]); app.factory( "AuthService", AuthService ); app.factory( "AuthInterceptor", AuthInterceptor ); app.config(["$httpProvider", function( $httpProvider){ $httpProvider.interceptors.push("AuthInterceptor"); }]); app.run(function ($rootScope, $location, AuthService) { $rootScope.$on('$routeChangeStart', function (event, next, current) { if (!AuthService.getToken()) { $rootScope.$evalAsync(function () { $location.path('/signin'); }) } }); }); function AuthService($localStorage, $http, $q) { return { getToken : function () { return $localStorage.token; }, setToken: function (token) { $localStorage.token = token; }, login : function (data) { $http.post(URL+"user/login", data); }, logout : function (data) { delete $localStorage.token; $q.when(); } }; } function AuthInterceptor($location, AuthService, $q ) { return { request: function(config) { config.headers = config.headers || {}; if (AuthService.getToken()) { config.headers['Authorization'] = 'Bearer ' + AuthService.getToken(); } return config; }, responseError: function(response) { if (response.status === 401 || response.status === 403) { $location.path('/signin'); } return $q.reject(response); } } }
When I run this error appears,
[$ injector: cdep] Circular dependency found: $ http -