【发布时间】: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