【问题标题】:Angular $http returning new values only onceAngular $http 只返回一次新值
【发布时间】:2013-05-31 18:31:09
【问题描述】:

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

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

谢谢!

【问题讨论】:

  • 为什么不从你的 ajax 调用中删除缓存:$templatecache
  • 呃!谢谢。当您复制/粘贴代码时,很容易忽略这样的事情。
  • 请采纳答案

标签: codeigniter rest angularjs


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    相关资源
    最近更新 更多