Javascript 这是一个带有ng repeat和ngInclude的bug吗?

Javascript 这是一个带有ng repeat和ngInclude的bug吗?,javascript,angularjs,Javascript,Angularjs,我试着像这样加载不同的模板 <div ng-class="{active:$first,in:$first,'tab-pane':true}" id="{{p.path}}_settings" ng-repeat="p in panes" ng-include="buildPath(p.path)"> </div> 它工作得很好。但现在我想禁用缓存,所以我这样做了 $scope.buildPath = function(path) { return 'templat

我试着像这样加载不同的模板

<div ng-class="{active:$first,in:$first,'tab-pane':true}" id="{{p.path}}_settings" ng-repeat="p in panes" ng-include="buildPath(p.path)">
</div>
它工作得很好。但现在我想禁用缓存,所以我这样做了

$scope.buildPath = function(path) {
  return 'templates/partials/settings_' + path + '.html?_=' + Date.now();
}
浏览器在加载重复页面时陷入困境


有什么想法吗?如果它是一个bug,您可以从缓存中删除以前的模板url(在本例中为
$templateCache
),而不是生成新的模板url

只需注入
$templateCache
并使用
remove
函数清除以前的URL即可:

$scope.buildPath = function(path) {
  var url = 'templates/partials/settings_' + path + '.html';
  $templateCache.remove(url);
  return url;
}
或者,这里有一条指令,您也可以用它装饰您的
div

app.directive('no-cache', ['$templateCache', function($templateCache) {
    var directive = {
        restrict: 'A',
        scope: false,
        link: function(scope, element, attrs) {
            scope.$parent.$watch(attrs.ngInclude, function(new, old){
                $templateCache.remove(old);
            });
        }
    };
    return directive;
}]);
app.directive('no-cache', ['$templateCache', function($templateCache) {
    var directive = {
        restrict: 'A',
        scope: false,
        link: function(scope, element, attrs) {
            scope.$parent.$watch(attrs.ngInclude, function(new, old){
                $templateCache.remove(old);
            });
        }
    };
    return directive;
}]);