Hello everyone, I'm wondering how I can manage user session ID and name across view controllers in AngularJS.
Here's the scenario: I made an HTTP call and retrieved the user ID and name. Now, I want to be able to access this information in any controller.
I attempted to use an Angular value service by setting:
app.value("user",{user_id:"0",user_name:"blank"})
And in a controller where the HTTP call is made:
app.controller("exampleCtrl",function($http,user){
user.user_id = data.user_id;
// Let's say the user ID is 4.
// Now user.user_id should also be 4
})
But, in another controller:
app.controller("nextCtrl",function(user){
console.log(user.user_id);
// This gives me 0 instead of 4
})
I expected it to return 4. Am I approaching this the wrong way? Is there a better way to achieve this? Please provide guidance.
Thank you!