0

我是 Angular 的新手,并在 Codeigniter 中使用 REST Api 配置设置了一个简单的示例,该配置返回一个 json(默认)线程列表。没问题!

直到,我向数据库添加更新。如果我清除/然后getThreads再次调用,我会收到相同的项目列表。页面刷新解决了这个问题。我可以在萤火虫中看到它只调用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";
            });
  };

我将如何使它始终调用新的数据列表而不是重用旧数据列表。

谢谢!

4

1 回答 1

2

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

于 2013-05-31T18:34:04.247 回答