私のアプリに問題があります。私は工場prepareStorage
を呼び出して、restApi
からすべての静的な変数を(ngStorage
を使用して)ブラウザストレージに保存しています。それはこのように思える:AngularJSすべてのルートについて工場出荷時の約束を解決します
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()
};
}]);
その後、私は私のストレージVARSを与える第二工場constantsService
、宣言している:
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;
}]);
をそして今、この時の私の悩みが来ます。
の再リフレッシュなしで、このストレージバーをコントローラ内に取得できません。つまり、最初のサイトの更新後に、コントローラ は
$localStorage.staticTypes.status
オブジェクトを検出しません。 2回目のリフレッシュを行う場合にのみ実行されます。
私は、$timeout
サービスの使用を避けるためのきれいな解決策を模索しています。
ありがとうございます。
こんにちは、ご協力いただきありがとうございます。私はそれを試しました - まず最初に、getStorage - > vm.getStorageなどのfexエラーを解決し、最後に返されたオブジェクトgetStorageはコントローラ内の呼び出しの後に定義されていません: constantsService.getStorage()でも応答は正しいです – Joeker
より良い?私はあなたが何を意味するのか理解できませんでした*最初にfxエラーを解決しました(例えばgetStorage - > vm.getStorage)そして最終的に返されるオブジェクトgetStorageはコントローラ内の呼び出しの後で定義されていません:constantsService.getStorage()でも応答は正しい* – AndreaM16
PS:apiServiceメソッド "call"の初期化は次のとおりです。 'code'call:function(メソッド、エンドポイント、ペイロード、成功、エラー、URL){} – Joeker