I am encountering an issue with local storage on my webpage. Upon initial visit, I am seeing an outdated value from local storage. However, upon refreshing the page, I am able to access the current value. How can I prevent this error and ensure that I only retrieve the most up-to-date local storage value every time? The code snippet provided attempts to address this issue without utilizing ngstorage. Do I need to install ngstorage in order to resolve this problem?
.controller('SignInCtrl', [
'$scope','$http' ,'$location','$window',
function($scope,$http, $location,$window) {
$scope.signin = function()
{
$http.post('***', userdetails).success(function(data,response)
{
var nameResponse = JSON.stringify(data.Name);
window.localStorage.setItem("name",nameResponse);
})
}
}])
.controller('MyprofileCtrl', [
'$scope','$http' ,'$location','$window',
function($scope,$http, $location,$window) {
var name=$window.localStorage.getItem("name");
//console.log(name);
if(name == null)
{
$scope.loginstatus ="Sign Up With Us";
console.log($scope.loginstatus);
}else
{
$scope.loginstatus ='Welcome '+ name.replace(/\"/g, "");
console.log($scope.loginstatus);
}
} ])