我正在將緩存添加到我的應用程序中,一切正常,緩存數據,使其過期並重新緩存。當我實現的把相同的過期數據,重新進行緩存的功能,如果沒有連接我得到這個錯誤: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