Angular $ http只返回一次新值

时间:2013-05-31 18:31:10

标签: codeigniter rest angularjs

我是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";
            });
  };

我如何制作它以便始终调用新的数据列表而不是重用旧的。

谢谢!

1 个答案:

答案 0 :(得分:2)

如果我正确理解了您的问题,您的ajax调用正在被缓存,因此您必须从代码中删除缓存:$ templatecache