❶ angularjs路由如何禁止缓存
angular默认的模板加载都会被缓存起来,使用的缓存服务是$tempalteCache,发送模板请求的服务是$templateRequest,可以有两种方案:搭运
1.每次发送$http请求模板完成后,调用$tempalteCache.remove(url)或removeAll清除所有模板缓存;
2.使用$provide.decorator改写原生的$templateRequest,禁掉缓存笑枝拆,$templateRequest的源码,可以看到它默认使用$tempalteCache作为缓存,可以去掉它碰枣。
❷ 如何解决AngularJs在IE下取数据总是缓存的问题
如果用AngularJs在IE下发出GET请求模行从后台服务取完Json数据再绑定到页面上显示的话,你可能会发现就算数据更新了,IE还是会显示原来的结果。实际上这时候IE的确是缓存了hashtag,没有再次去做HttpGET请求最新的数据。x0dx0a最直接的办法是在后台撸掉OutputCache,但这种做法余模并不推荐,需要改每一处被Angular调用的地方,代价太大。这种问题应该在前端解决最好。研究了一会儿总结了最有效的旦毁哗解决方法,并不需要改后台代码了。x0dx0a在你的appconfig里撸一个$httpProvider进去,比如像我这样,和路由可以配在一起,当然分开配也没问题。x0dx0avarconfig=["$routeProvider","$httpProvider",function($routeProvider,$httpProvider){x0dx0a//(!$httpProvider.defaults.headers.get){x0dx0a$httpProvider.defaults.headers.get={};x0dx0a}x0dx0a//EnablesRequest.IsAjaxRequest()inASP.NETMVCx0dx0a$httpProvider.defaults.headers.common["X-Requested-With"]='XMLHttpRequest'x0dx0a//$httpProvider.defaults.headers.get['Cache-Control']='no-cache'x0dx0a$httpProvider.defaults.headers.get['Pragma']='no-cache'x0dx0a$routeProvider.when("/",{templateUrl:"Manage/dashboard/index.cshtml"})x0dx0a.when("/dashboard",{templateUrl:"Manage/dashboard/index.cshtml"})x0dx0a.when("/dashboard/serverinfo",{templateUrl:"Manage/dashboard/serverinfo.cshtml"})x0dx0a.when("/dashboard/emaillogs",{templateUrl:"Manage/dashboard/emaillogs.cshtml"})x0dx0a//othercode....x0dx0a.otherwise({redirectTo:"/"});x0dx0a}];x0dx0aapp.config(config);x0dx0ax0dx0a最关键的就是最后的禁用IE对ajax的缓存x0dx0a$httpProvider.defaults.headers.get['Cache-Control']='no-cache'x0dx0a$httpProvider.defaults.headers.get['Pragma']='no-cache'x0dx0ax0dx0a如果你想这样写,是会爆的:x0dx0a$httpProvider.defaults.headers.get['If-Modified-Since']=Ɔ'x0dx0ax0dx0a这样会导致include指令加载的partialview撸不出来,所以不要作死了