내 응용 프로그램에 문제가 있습니다. 나는 prepareStorage
을 호출하여 모든 정적 바를 restApi
에서 브라우저 저장소 (ngStorage
사용)로 저장하는 공장을 가지고 있습니다. 다음과 같이 보인다 :이 경우 내 문제가되어 지금AngularJS 모든 경로에 대한 일부 공장 약속을 해결하십시오.
angular.module('panelApp')
.factory('constantsService', ['$localStorage', '$q', 'prepareStorage', '$timeout',
function($localStorage, $q, prepareStorage, $timeout) {
var output = {};
var deferred = $q.defer();
$timeout(function() {
deferred.resolve(prepareStorage.load, function() {
output = {
status: $localStorage.staticTypes.status
};
});
}, 1000);
return output;
}]);
을 그리고 :
angular.module('panelApp')
.factory('prepareStorage', ['$localStorage', '$sessionStorage', 'apiService',
function($localStorage, $sessionStorage, apiService) {
var promise = {};
var load = function() {
apiService.call('head', 'staticTypes.json', [], function(response, status, head) {
if(angular.isUndefined($localStorage.staticTypes) || $localStorage.staticTypes.updatedAt < new Date(head()['last-modified'])){
delete $localStorage.staticTypes;
promise = apiService.call('get', 'statictypes.json', [], function (response) {
$localStorage.staticTypes = response;
}, function (errorObj) {
console.log(errorObj.error.message);
});
}
});
return promise;
return {
load: load()
};
}]);
가 그럼 난 바르 나에게 스토리지를 제공하는 두 번째 공장
constantsService
을 선언했다.
안녕하세요 다시 새로 고침없이 컨트롤러 내에서이 저장소 바이스를 가져올 수 없습니다. 즉, 첫 번째 사이트 새로 고침 후 컨트롤러는
$localStorage.staticTypes.status
개체를 찾지 못합니다. 두 번째 새로 고침 만 수행하면됩니다.
$timeout
서비스 사용을 피하는 깨끗한 해결책을 찾고 있습니다.
미리 감사드립니다.
안녕하세요, 귀하의 도움에 감사드립니다. 내가 시도 - fst 오류 (예 : getStorage -> vm.getStorage)를 해결하고 마지막으로 반환 된 객체 getStorage는 컨트롤러 내부에서 호출 한 후 정의되지 않았습니다. constantsService.getStorage() 하지만 응답도 정확합니다. – Joeker
안녕하세요. 보다 나은? 나는 당신이 * 무엇을 의미하는지 이해하지 못했다 (예를 들어 getStorage -> vm.getStorage) 그리고 마지막으로 리턴 된 객체 인 getStorage는 컨트롤러 내부에서 호출 후 정의되지 않는다 : constantsService.getStorage() 그러나 응답 또한 정확하다 * – AndreaM16
추신 : apiService 메서드 "호출"은 다음과 같은 초기화가 있습니다 : 'code'call : function (메서드, 끝점, 페이로드, 성공, 오류, URL) {} – Joeker