After utilizing local storage, I encountered an issue where upon logging in and being redirected to the myprofile page, the local storage value was not loading properly. Instead, I was getting a null value. It wasn't until I manually reloaded the page that the local storage retrieved the correct value. How can I go about fixing this?
.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);
$location.path('/myprofile');
})
}
}])
.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);
}
}])