0

我的应用程序正在连接到 nodejs 后端进行身份验证,工厂和配置如下

angular.module('app.services', [])
.factory('AuthInterceptor', [function($rootScope, $q, AUTH_EVENTS) {
  return {
    responseError: function(response) {
      $rootScope.$broadcast({
        401: AUTH_EVENTS.notAuthenticated,
      }[response.status], response);
      return $q.reject(response);
    }
  };
}])
.service('AuthService', [function($q, $http, API_ENDPOINT) { 
// some methods
])}
.config([function($httpProvider) {
  $httpProvider.interceptors.push('AuthInterceptor');
}]);

起始页面是登录页面,但我面临控制台错误的空白页面

 ionic.bundle.js:8900 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module app.services due to:
TypeError: Cannot read property 'interceptors' of undefined
    at http://localhost:8100/js/services.js:94:16

services,js 中的第 94:16 行是:$httpProvider.interceptors.push('AuthInterceptor');

我该如何解决

4

1 回答 1

0

您忘记在调用中提供依赖字符串config

.config(['$httpProvider', function($httpProvider) {
  $httpProvider.interceptors.push('AuthInterceptor');
}]);
于 2016-03-19T02:18:09.183 回答