如何禁用角度缓存

时间:2016-03-11 10:37:45

标签: javascript angularjs caching angular-ui-router

我在控制器中有两个功能,它们连接到视图中的两个复选框。问题是,每当我对这些功能进行任何更改时,浏览器都无法检测到。我甚至完全删除了这两个功能,浏览器的行为就像它们仍在那里一样。这种情况发生在所有firefox和chrome

我在网上进行了一些研究,在我看来这是角度缓存模板的问题。我做use ui-router但到目前为止

我删除了我的浏览器缓存,但它没有解决问题

我添加了此代码但似乎没有任何帮助

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

我的代码:

    <div class="checkbox">
            <label class='checkboxes' id='checkbox_1'>
            <input type="checkbox" ng-model="thirtyDay" ng-change="changeAxis1()">
            Last 30 days
            </label>
             <label class='checkboxes' id='checkbox_2'>
            <input type="checkbox" ng-model="wholeTimeline" ng-change="changeAxis2()">
            Election timeline
            </label>
             </div>

控制器:

  $scope.wholeTimeline = true;

         $scope.changeAxis2 = function() {
                if($scope.wholeTimeline) {
                        $scope.thirtyDay = false;

                        alert('is checked')

                    } else {
                    alert('is unchecked')
                    }
        };



        $scope.changeAxis1 = function() {
            if ($scope.thirtyDay) {
                        $scope.wholeTimeline = false;
                        alert('is checked')

                    }else {
                    alert('is unchecked')
                    }
        };

1 个答案:

答案 0 :(得分:1)

您是否尝试在firefox / chrome中使用匿名/隐身模式。

根据这个,缓存永远不会在该模式下使用: https://www.quora.com/Does-incognito-mode-on-Chrome-use-the-cache-that-was-previously-stored