是否有可能拦截angularjs使用HTML,CSS和JS文件? [英] Is it possible to intercept html, css and js files used in angularjs?

查看:232
本文介绍了是否有可能拦截angularjs使用HTML,CSS和JS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个HTTP拦截器,并根据我的观察,它仅适用于所有使用$ HTTP服务。如果我想拦截即使在模板中使用的CSS,HTML和JS文件?这可能吗?

I have already created an http interceptor and based on my observation, it only applies to all that uses $http service. What if I want to intercept even the css, html and js files used in the template? Is it possible?

这是我上面提到的拦截器的code:

This is the code of the interceptor I mentioned above:

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(模板)拦截器只是像上面的。

I want to be able to do an interceptor for css, html and js (for template) just like the one above.

推荐答案

正如你所说的,

它仅适用于所有使用$ http服务

it only applies to all that uses $http service

所以,如果你想截取对HTML,CSS和JS文件的请求。它是在服务器上最好完成,而不是在客户端。

So, if you want to intercept the requests for html,css and js files. It is best done on the server, rather than the client.

这篇关于是否有可能拦截angularjs使用HTML,CSS和JS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆