I'm currently developing a Spotify application. I've successfully implemented the login functionality and obtained my token. However, I have encountered an issue where I am unable to access a specific variable outside of a method, in this case being "getCurrentUser".
Below is the method causing me trouble:
function getUser() {
if ($localStorage.token == undefined) {
throw alert("Not logged in");
} else {
Spotify.getCurrentUser().then(function(data) {
var names = JSON.stringify(data.data.display_name);
console.log(names)
})
}
};
Although I am able to log the name variable correctly in the console, when I call the getUser() function, it returns undefined
. Even with attempting to return the names variable, I still encounter the same issue.
The solution I am seeking involves utilizing $scope
for that variable.