【问题标题】:How to disable template cacheing in Angular2如何在 Angular 2 中禁用模板缓存
【发布时间】:2016-03-09 14:54:53
【问题描述】:

有没有办法在 Angular 2 中禁用模板缓存?

我正在 Angular2 中创建一个单页应用程序。我的应用程序有三个页面。所以我使用路由从一个页面切换到另一个页面。在我的一个页面中,我有一个提交按钮。我需要根据用户选择的值禁用它。我的问题是,一旦我将其禁用,它将保持禁用状态,直到我刷新页面。当我返回到同一页面时它不会启用。这是因为模板缓存。 Html 页面加载后不会重新加载。

有没有办法禁用缓存或重新加载模板?

谢谢

【问题讨论】:

标签: caching angular angular2-routing angular2-template


【解决方案1】:

问题现已解决。由于 Angular 2 beta.0 版本而发生缓存。现在我将其更新为 beta.13。它现在正在工作。

【讨论】:

    【解决方案2】:

    请尝试以下链接来解决您的问题:

    AngularJS disable partial caching on dev machine

    How to clear template cache

    或者你可以试试这个代码:

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

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2016-10-01
      • 2013-06-03
      • 1970-01-01
      • 2011-03-06
      • 2018-05-13
      • 1970-01-01
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多