Some application state information need to be stored in an Angular service so as to be globally accessed.
app.value('identity', {});
Then in a controller of my first view after log in. I make a GET api call to collect application state info from the server side. In the success callback, transfer the data into my global variable (service).
function successCallback(data) {
identity.username = data.username;
identity.email = data.email;
}
I assumed the identity will hold the data throughout my application. But it is not the case! In my other views, I inject identity into the controller
app.controller('anotherController', ['identity', anotherController];
function anotherController(identity){
// access identity here.
$scope.username=identity.username;
}
The first time I came to that view. username is correctly displayed on the page. But after a refresh, it appears the identity is null again! What can we do to make the value really persistent?
localStorage.