【发布时间】:2016-11-17 02:05:02
【问题描述】:
我将 Spring Boot 用于我的应用程序的后端。当用户在使用网站期间失去授权或后端向客户端发送 401 代码时,我正在尝试进行重定向。
我在我的配置文件中使用了拦截器:
var app = angular.module('myApp', [
'ngRoute', 'ngResource','ngDialog', 'tableSort', 'ngMaterial', 'ngMessages', 'timer', 'config'
]).config(function ($routeProvider, $httpProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'LoginCtrl'
})
.when('/main', {
templateUrl: 'views/main.html',
controller: 'LoginCtrl'
})
.when('/home', {
templateUrl: 'views/home.html',
controller: 'UserAccount'
})
.when('/search', {
templateUrl: 'views/find_document.html',
controller: 'findDocument'
})
.otherwise({redirectTo: '/'});
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
var interceptor = ['$rootScope', '$q', function(scope, $q) {
function success(response) {
return response;
}
function error(response) {
var status = response.status;
if (status == 401) {
window.location = "/nologin"
return;
}
return $q.reject(response);
}
return function(promise) {
return promise.then(success, error);
}
}];
$httpProvider.responseInterceptors.push(interceptor);
});
当我尝试此代码时,控制台日志中出现错误
错误:
angular.js:38 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=myApp&p1=Error%3A%2…Flocalhost%3A8080%2Fbower_components%2Fangular%2Fangular.min.js%3A21%3A179)(…)
问题出在哪里?
编辑:
来自 url 的错误日志
Failed to instantiate module myApp due to:
TypeError: Cannot read property 'push' of undefined
at http://localhost:8080/js/App.js:115:39
at Object.invoke (http://localhost:8080/bower_components/angular/angular.min.js:41:456)
at d (http://localhost:8080/bower_components/angular/angular.min.js:39:418)
at http://localhost:8080/bower_components/angular/angular.min.js:40:19
at q (http://localhost:8080/bower_components/angular/angular.min.js:7:355)
at g (http://localhost:8080/bower_components/angular/angular.min.js:39:319)
at cb (http://localhost:8080/bower_components/angular/angular.min.js:43:336)
at c (http://localhost:8080/bower_components/angular/angular.min.js:20:390)
at Bc (http://localhost:8080/bower_components/angular/angular.min.js:21:179)
at fe (http://localhost:8080/bower_components/angular/angular.min.js:20:1
【问题讨论】:
-
你有 html 中所有这些依赖的引用吗?
-
究竟是什么?这是我的html文件github.com/MarcinLenda/WzB/blob/master/src/main/resources/…
-
@Sajeetharan 我想我都有了
标签: angularjs