AngularJS会缓存它,有没有办法防止它?

时间:2014-06-12 08:04:38

标签: javascript angularjs caching angularjs-scope

var modalInstance = $modal.open({
    templateUrl: '/template/edit-modal.html',
    controller: ModalInstanceCtrl2,
    resolve: {
        locations: function () {
            return locationToEdit;
        }
    },
    scope: $scope.$new()
});

我有一些使用上述脚本打开的模态窗口。它可以创造奇迹,但我注意到的是,在某些浏览器中,浏览器正在缓存templateUrl,并且只有在清除缓存时才会看到对html文件所做的任何更改。

有没有办法防止这种情况发生,因为在任何给定时间模态都可能发生变化?

2 个答案:

答案 0 :(得分:0)

尝试实施任何缓存清除技术。 最简单的一个没有任何缓存的是将冗余和更改的GET参数添加到url:

templateUrl: '/template/edit-modal.html' + '?a=' + Math.random()

更好的技术是使用"?version =" ,其中版本将是您的系统决定的一些字符串,这样每当模板更改时版本都会更改。

答案 1 :(得分:-1)

我在应用程序中使用$templateCache.removeAll();解决了这个问题。

相关问题