【问题标题】:How to clear template cache in angularjs如何清除angularjs中的模板缓存
【发布时间】:2017-02-08 05:51:56
【问题描述】:

在 Angularjs 中,我为项目制作了许多 html 页面。但是在一个浏览器中,html 页面来自缓存,因此我无法在该浏览器中获得新的更改(进行刷新和硬刷新)。

在硬刷新页面后有时我会在 html 中得到新的更改,而有时我没有得到它。

请给我一些解决方案。

我的缓存示例:-

mainApp.run(['$rootScope','$cacheFactory', function($rootScope,$cacheFactory) {
$cacheFactory.get('$http').removeAll()
.....
....
}

【问题讨论】:

    标签: html angularjs browser-cache


    【解决方案1】:

    如果你想从代码中移除缓存的视图。

    app.run(function($rootScope, $templateCache) {
        $rootScope.$on('$routeChangeStart', function(event, next, current) {
            if (typeof(current) !== 'undefined'){
                $templateCache.remove(current.templateUrl);
            }
        });
    });
    

    【讨论】:

    • 我这样做了,但我还有一个问题是,如果我们更改 html 中的某些内容.. 可以在不重新加载或刷新页面的情况下获取该内容。
    • @arshadshaikh 因为你需要使用构建系统,或者你可以使用诸如 atom 或 webstrom 之类的 ide
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 1970-01-01
    • 2011-11-28
    相关资源
    最近更新 更多