I'm working on a Spotify app. I'm able to login and get my token. My problem is I cannot access a variable outside the method. In this case "getCurrentUser"
This is my method:
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)
})
}
};
As you can see I console.logged the name and I do get the right value in the console. But only works there if I call the function getUser()
I get undefined
even with a return of the names variable.
I need to $scope
that variable.
return names
, but you also needreturn Spotify.getCurrentUser()...
so that it returns the promise (and ultimately the return value from the then) – Mince