在$httpinterceptor中使用$state可以工作,但编译失败(AngularJS+;TypeScript)
我的httpinterceptor在angularJS和typescript中有问题。 我使用ui.router并在出现错误401时重定向到我的登录页面 它正在工作,但我的控制台中有错误:“angular.min.js:497 error:[$compile:tpload]” 为什么我会有这个错误 这是我的代码:在$httpinterceptor中使用$state可以工作,但编译失败(AngularJS+;TypeScript),angularjs,typescript,Angularjs,Typescript,我的httpinterceptor在angularJS和typescript中有问题。 我使用ui.router并在出现错误401时重定向到我的登录页面 它正在工作,但我的控制台中有错误:“angular.min.js:497 error:[$compile:tpload]” 为什么我会有这个错误 这是我的代码: module Security { export class AuthentificationInterceptor { private static instance:
module Security {
export class AuthentificationInterceptor {
private static instance: AuthentificationInterceptor;
constructor(private $q: ng.IQService, private $injector: ng.auto.IInjectorService) { }
public static Factory($q: ng.IQService, $injector: angular.auto.IInjectorService) {
AuthentificationInterceptor.instance = new AuthentificationInterceptor($q, $injector);
return AuthentificationInterceptor.instance;
}
public response = (response):ng.IHttpPromise<any> => {
var vm = Security.AuthentificationInterceptor.instance;
console.log(response);
return response || vm.$q.when(response);
}
public responseError = (error):ng.IHttpPromise<any> => {
var vm = Security.AuthentificationInterceptor.instance;
console.log(error);
if (error.status === 401) {
let $state: ng.ui.IStateService;
$state = vm.$injector.get('$state') as ng.ui.IStateService;
$state.go('login');
};
return vm.$q.reject(error);
}
}
模块安全性{
导出类AuthenticationInterceptor{
私有静态实例:authenticationinterceptor;
构造函数(私有$q:ng.IQService,私有$injector:ng.auto.IInjectorService){}
公共静态工厂($q:ng.IQService,$injector:angular.auto.iinjector服务){
authenticationinterceptor.instance=新的authenticationinterceptor($q,$injector);
返回authenticationInterceptor.instance;
}
公共响应=(响应):ng.ihttpromise=>{
var vm=Security.authenticationinterceptor.instance;
控制台日志(响应);
返回响应| | vm.$q.when(响应);
}
公共响应错误=(错误):ng.ihttpromise=>{
var vm=Security.authenticationinterceptor.instance;
console.log(错误);
如果(error.status==401){
让$state:ng.ui.IStateService;
$state=vm.$injector.get(“$state”)作为ng.ui.IStateService;
$state.go('login');
};
返回vm.$q.reject(错误);
}
}
}我认为你的错误不在拦截器中。您确定您的登录页面工作正常吗?在我看来,angular无法加载模板(登录模板?),我使用ASP MVC。我的页面登录是一个测试,我刚刚在部分视图中登录。这很奇怪。模板本身不是问题所在。问题是angular找不到它(404Not found应该记录在浏览器开发工具的网络选项卡中)是我的页面测试,我将我的筛选器放在其中授权找不到,因为筛选器阻止访问。我的网页登录后工作。错误在PartialViewResult Test()中。突破点永远不会重新出现。