❶ 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擼不出來,所以不要作死了