각도의 http 캐시를 사용하려고하지만 결과가 정의되지 않았습니다. 캐시는 객체를 반환하지만 usersCache는 정의되지 않습니다. data.js에 main.js에서
가제어기
app.controller('exploreController', function($scope, dataService, $cookies, $cacheFactory, $http) {
// dataService.explorePosts();
$scope.explore = function(){
dataService.explorePosts();
var cache = $cacheFactory.get('$http');
console.log(cache);
var usersCache = cache.get('http://dstm.herokuapp.com/api/explore');
console.log(usersCache);
};
$scope.explore();
});
서비스
angular.module('dsnApp')
.service('dataService', function($http, $cookies, $cacheFactory) {
this.explorePosts = function(){
var id = $cookies.get("userId");
$http.get('http://dstm.herokuapp.com/api/explore', {cache: true,
params: {userId: id, page: 1},
})
.then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
console.log(response);
});
};
컨트롤러 * *? – MACMAN
당신이 작업 ** plnkr를 만들 수 있습니다 – Aravind
$ http 비동기입니다. 요청이 완료되어 동 기적으로 캐시에 액세스하려고 시도 할 때까지는 캐시되지 않습니다. – charlietfl