在AngularJS中,可以通过缓存清除和版本控制来解决加载已过期HTML文件的问题。以下是一个解决方法的代码示例:
My Angular App
// app.js
var myApp = angular.module('myApp', []);
myApp.config(['$provide', function ($provide) {
$provide.decorator('$templateRequest', ['$delegate', function ($delegate) {
// Disable template caching
$delegate('setTrustedHtml', function (tpl) {
return $delegate(tpl + '?v=' + Math.random());
});
return $delegate;
}]);
}]);
myApp.controller('myCtrl', function ($scope) {
// Your controller logic goes here
});
通过在HTML模板文件中添加版本号,并在AngularJS应用的配置中禁用模板缓存,可以确保每次部署新版本时,浏览器会强制重新加载已过期的HTML文件,从而避免加载不存在的文件。