2013-05-31 56 views
0

我是Angular的新手,並且在Codeigniter中設置了一個REST Api配置的簡單示例,該示例返回一個json(默認)線程列表。沒問題!

直到我向數據庫添加更新。如果我清除/然後再次撥打getThreads,我會收到相同的物品清單。頁面刷新解決了這個問題。我可以在firebug中看到它每頁加載只調用一次url:api/example/threadlist/id/'x'

function ThreadsCtrl($scope, $http, $templateCache) { 
    $scope.getThreads = function(id) { 
     if (!id) { id = 'reset'; } 
     $http({method: 'GET', url: 'api/example/threadlist/id/' + id, cache: $templateCache}). 
      success(function(data) { 
       $scope.threadslist = data;     //set view model 
      }). 
      error(function(data) { 
       $scope.threadslist = data || "Request failed"; 
      }); 
    }; 

我該如何使它總是調用一個新的數據列表,而不是重複使用舊數據。

謝謝!

+2

爲什麼不ü刪除緩存:從你的Ajax調用 –

+0

咄$ templatecache!謝謝。當你複製/粘貼代碼時,很容易忽略這樣的事情。 –

+0

請接受答案 –

回答

2

如果我理解你的問題正確的Ajax調用被緩存,因此你必須刪除緩存:從您的代碼$ templatecache