【发布时间】:2015-04-15 15:14:01
【问题描述】:
我已经创建了一个 http 拦截器,根据我的观察,它只适用于所有使用 $http 服务的人。如果我想拦截模板中使用的 css、html 和 js 文件怎么办?有可能吗?
这是我上面提到的拦截器的代码:
app.factory('redirectInterceptor', function($q,$location,$window){
return {
'response':function(response){
if (typeof response.data === 'string' && response.data.indexOf("My Login Page")>-1) {
$window.location.href = "/login.html";
return $q.reject(response);
}else{
return response;
}
}
}
});
app.config(['$httpProvider',function($httpProvider) {
$httpProvider.interceptors.push('redirectInterceptor');
}]);
我希望能够像上面那样为 css、html 和 js(用于模板)做一个拦截器。
【问题讨论】:
-
您正在尝试做的事情,似乎更适合服务器端实现。
-
可以拦截html文件
-
@Chandermani 当会话到期并且我尝试访问需要身份验证的页面时,该页面将为空白。当我使用 firebug 进行调试时,我可以看到一些 css 和 js 正在被调用,但响应是 302。但是没有发生重定向。我想做一个拦截器,它会做和我发布的代码一样的事情。
-
Angular 中没有这方面的内容。但是看看有没有浏览器的js api。
-
@entre 怎么样? js和css呢?
标签: angularjs angular-http-interceptors