【发布时间】:2016-02-23 17:08:21
【问题描述】:
如何删除使用 AngularJS 的 HTML 中的浏览器缓存?我在 index.html 中使用了以下内容。我也尝试在我的 app.js 中使用$templateCache,但没有用。
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/login',{templateUrl: '/partials/login.html',controller:'loginCtrl'});
$routeProvider.when('/fingerprint',{templateUrl: '/partials/fingerprint.html',controller:'fingerprintCtrl',resolve: {
factory: checkRouting
}});
$routeProvider.otherwise({redirectTo: '/login'});
}]).
run(function($templateCache) {
$templateCache.removeAll();
});
var checkRouting= function ($q, $rootScope, $location,$http) {
if ($rootScope.loggedUser) {
return true;
} else {
var deferred = $q.defer();
$http.post("#/fingerprint", { userToken: "blah" })
.success(function (response) {
$rootScope.loggedUser = response.loggedUser;
deferred.resolve(true);
})
.error(function () {
deferred.reject();
$location.path("/");
});
return false;
}
};
任何帮助将不胜感激!
【问题讨论】:
-
浏览器缓存没有被自动删除。用户每次登录时都必须手动删除它才能看到更改。
标签: html angularjs browser-cache