我正在使用一些常見問題解答頁面,我正在使用angular localstorage保存數據。 然後,我將所有文件上傳到服務器,與其他人共享。 當我這樣做時,我放棄了數據,並得到它。這是我第一次上傳,所以它不能在那裏。然後我插入一些數據,並且它工作正常,即使我關閉瀏覽器並再次打開它,我的數據也在那裏。上傳新頁面時丟失了AngularJs Localstorage數據
但是當我再次上傳我的.html文件到服務器時,我再次鬆開它。這是相同的網址,相同的HTML頁面,但一些角度localstorage類中的數據如何重新設置。
我是新角度,我第一次使用localstorage。我已經搜索這個問題,但沒有找到任何提示。
如何將數據保存在localstorage中?
我的角模塊中的代碼是:
變種應用= angular.module( 'WikiCTTXApp',[ 'ngSanitize', 'ngStorage']);
app.controller( 'InfoInterController',函數($範圍,$的localStorage,sessionStorage的$){
$scope.$storage = $localStorage;
$scope.InfoInter = $localStorage.InfoInter;
$scope.newInfoInter = {};
$scope.addInfoInter=function(){
/* AD(added later): I added this line to test and initialize the variable and my issue disapeard */
if (typeof($scope.InfoInter) == 'undefined'){$scope.InfoInter=[]};
$scope.InfoInter.push($scope.newInfoInter);
$scope.newInfoInter = {};
$scope.save();
};
$scope.remove = function(item) {
var index = $scope.InfoInter.indexOf(item);
$scope.InfoInter.splice(item, 1);
};
$scope.save = function() {
$localStorage.InfoInter = $scope.InfoInter;
};
$scope.load = function() {
$scope.InfoInter = $localStorage.InfoInter;
};
});
請分享一些代碼,您可以在其中獲取''''設置'localStorage'數據。 – Faisal
剛剛添加我的代碼角模塊 –