Error with angle intercerptors

0

I'm trying to implement an authentication system with Angular + json web token, but how much do I try to make a $http.interceptors.push('nomeDo Interceptor') show error in the application and in the browser console does not show any errors.

Follow some parts of the code.

The interceptor

angular.module('digApp').factory('authInterceptor', function(){
  return {
    request: function(config){
      console.log(config);
      return config;
    }
  }
});

The Interceptor Setting

angular.module('digApp').config(function($httpProvider){
  $httpProvider.interceptors.push("authInterceptor");
});

For now I'm only displaying what comes from the config, but it is not working, the application blocks the link requests that it does to api . And it does not show console.log () , nor does it load ng-view views ;

If someone has a good tutorial Angular Login System + jwt + nodejs I am grateful.

    
asked by anonymous 19.10.2016 / 09:21

1 answer

0

Apparently everything is OK! Try replacing the interceptor code with this

Interceptor.js

(function() {
    'use strict';

    angular
        .module('digApp')
        .factory('authInterceptor', authInterceptor);

    authInterceptor.$inject = ['$q'];

    function authInterceptor($q) {
        return {
            request: request,
            response: response,
            requestError: requestError,
            responseError: responseError
        };

        function request(config) {
            var url = config.url;
            return config;
        }

        function response(response) {
            var url = response.config.url;
            return response;
        }

        function requestError(rejection) {
            return $q.reject(rejection);
        }

        function responseError(rejection) {
            return $q.reject(rejection);
        }
    }
})();
    
20.10.2016 / 14:50