我正在将缓存添加到我的应用程序中,一切正常,缓存数据,使其过期并重新缓存。当我实现的把相同的过期数据,重新进行缓存的功能,如果没有连接我得到这个错误:Cannot read property 'then' of undefined
angularJS/ionic无法读取未定义属性'then'
这里是我的Controler代码:
.controller('ItemsCtrl', function($scope, $http, DSCacheFactory) {
//handle the catche to hold the items lits.
self.itemsCache = DSCacheFactory.get("itemsCache");
/*
*Fcuntion to re-refresh the cach after expire
*re-use the old cache if no internet connection available
*/
self.itemsCache.setOptions({
onExpire: function(key, value){
getItems()
.then(function(){
console.log("Items Cache was automatically refreshed", new Date());
}, function(){
console.log("Errorgetting data put expired item back in the cache", new Date());
});
}
});
function getItems(){
var cacheKey = "items",
itemsData = self.itemsCache.get(cacheKey);
if(itemsData){
// if data in the cache dont make HTTP calls.
console.log("Found Data in cache", itemsData);
//recive Data from the cache
$scope.items = itemsData;
}
else{//if no data in the catch make HTTP calls.
//HTTP request to get the items data.
$http.get('services/data.json')
.success(function(data){
console.log("Recived data via HTTP");
//caching the data recived from the http calls.
self.itemsCache.put(cacheKey, data);
$scope.items = data;
});
}//end of the else statment
}
getItems();
})
我想你的解决方案没有奏效,我也尝试应用概念,指出错误的方式ALS,没有工作仍然infinate HTTP调用和undifined同样的错误生病后我soultion这并无法正常工作一个答案 – 2015-02-24 13:33:29