$http.post - Uncaught ReferenceError: cache is not defined
שלום,
דרך Angular
אני משתמש בcache על מנת לשמות את הנתונים המתקבלי מservice.
אני מצליח ךהכניס לcache אבל בפעם הבאה שאני מגיע לפונקציה, הנתונים לא קיימים.
ז"א לאחר סיום התהליך הcache נמחק.
תודה על העזרה
שלום,
דרך Angular
אני משתמש בcache על מנת לשמות את הנתונים המתקבלי מservice.
אני מצליח ךהכניס לcache אבל בפעם הבאה שאני מגיע לפונקציה, הנתונים לא קיימים.
ז"א לאחר סיום התהליך הcache נמחק.
תודה על העזרה
קוד:
var myCache = $cacheFactory('myCache');
var cacheData = myCache.get('HeaderMenu');
//function
var _getHeaderMenu = function (idNum, token) {
var deferred = $q.defer();
//כאן תמיד המשתנה הוא ריק
if (!cacheData) {
$http.post(serviceBase + 'XXXXXXX', JSON.stringify(data),
{
cache: myCache,
headers: {
'Content-Type': 'application/json',
'token': token
}
}
).then(function (response) {
cacheData = response;
// insert data to cache
myCache.put('HeaderMenu', cacheData);
deferred.resolve(response);
},
function (error) {
deferred.reject(error.data)
});
}
return deferred.promise;
}