I have developed a basic factory to store a value from my authService:
app.factory("subfactory",
function() {
var subValue = {};
return {
set: set,
get: get
};
function get() {
return subValue;
}
function set(value) {
subValue = value;
}
});
I am storing the value like this in authservice - this code snippet demonstrates how I save the value using subfactory.set()
:
mgr.getUser().then(function (user) {
if (user) {
var idToken = user.id_token;
var dataIdToken = getDataFromToken(idToken);
subfactory.set(dataIdToken.sub);
} else {
//console.log("User not logged in");
}
});
However, when I attempt to retrieve the object in the controller, it appears to be empty:
vm.onGridLoad = function() {
var storedValue = subfactory.get();
console.log(storedValue);