I am facing an issue with passing a variable into a service that needs to be accessed from multiple states within my application. I have created a service and attempted to pass a variable from a controller into the service in order to access it from another state and utilize it in other functions as well.
My code snippet is as follows:
The controller receives input from an HTML form and uses it in a function. I also aim to store the value obtained from the input inside a service for further use in other functions.
$scope.submit = function()
{
var input = document.getElementById('userCode').value;
var current;
for(var i = 0; i < json.details.length; i++){
current = json.details[i];
if(current.pin == input){
$state.go('LogInHome');
$scope.Current = currentUser;
$scope.Current.currentUser = input;
}
}
console.log(current.currentUser);
}
Below is the code for the service:
App.service('currentUser', function ()
{
return{};
});
Upon checking the console, I notice that I am getting an "Undefined" output. Can anyone point out where I might be going wrong?