저는 현지화 쿠키를 사용하여 현재 문화를 추적하고 있습니다. 응용 프로그램이 시작될 때 현재 선택한 문화권의 모든 메시지를로드하고 해당 문화권에 대한 정보와 함께 localStorage
에 보관 한 다음 선택한 문화권이 변경 될 때만 새로 고침 (localStorage
의 값이 'CurrentCulture'
인 경우에만 새로 고침합니다. 쿠키에서). AngularJs에서 데이터를로드 할 수 있도록 다른 실행이 종료 될 때를 어떻게 확인할 수 있습니까?
getLocalisationsFromServer
완료하기 전에
app.service("localisationService", function ($q, $http, localStorageService) {
var getCachedMessagesForLanguage = function (localisationMessagesUrl, language) {
console.log('getCachedMessagesForLanguage');
var messages = localStorageService.get('Localisation');
if (!messages || language !== localStorageService.get('Language')) {
getLocalisationsFromServer(localisationMessagesUrl).then(function (serverMessages) {
localStorageService.add('Localisation', messages);
localStorageService.add('Language', language);
});
}
return localStorageService.get('Localisation')
}
function getLocalisationsFromServer(localisationMessagesUrl) {
return $q(function (resolve) {
$http.get(localisationMessagesUrl)
.then(function (response) {
resolve(response.data);
});
});
}
return {
messages: function (localisationMessagesUrl, language) {
return getCachedMessagesForLanguage(localisationMessagesUrl, language);
}
};
});
getCachedMessagesForLanguage
반환 undefined
을 가지고 localisationService
에서 $scope.messages = localisationService.messages(localisationMessagesUrl, currentCulture);
을 설정합니다. 페이지를 새로 고침하면 제대로 표시됩니다. 이 문제를 어떻게 해결할 수 있습니까?