我有一个简单的DataFactory检索一些职位:
dataFactory.getPosts = function() {
if (this.httpPostsData == null) {
this.httpPostsData = $http.get("http://localhost/matImms/wp-json/posts?type=journey&filter[posts_per_page]=-1&filter[order]=ASC&filer[orderby]=date")
.success(function (posts) {
})
.error(function (posts) {
console.log('Unable to load post data: ' + JSON.stringify(posts));
});
}
return (this.httpPostsData);
}
控制器调用该工厂,并据我所知,职位的承诺 - 所以有一些东西无论如何,都取得了成功并完成了一些东西。这工作正常。
.controller('CardsCtrl', function($scope, dataFactory,
$ionicSlideBoxDelegate, $stateParams) {
var parentID = $stateParams.parentID;
var keyIDNumber = $stateParams.keyID;
$scope.card = [];
var httpcall = dataFactory.getPosts()
.success(function (posts) {
$scope.card = dataFactory.getChildPosts(parentID, posts, keyIDNumber);
$ionicSlideBoxDelegate.update();
});
// do other stuff ......
});
不过,我现在正在试图缓存后的数据 - 但是当控制器被称为第二次则返回错误.success是不是一个函数。我认为这是因为帖子已经被退回 - 但我该如何处理?