Hi I am having difficulty with having a function inside a controller in angular return a value to a variable.
Here is the function:
var getUser = function(user_id, key) {
var user;
var request = {
method: 'GET',
url: 'http://localhost/torteez/api/user/' + user_id,
headers: {
'Content-Type': 'application/json'
}
};
$http(request)
.then(function successCallback(response) {
if(key === 'all') {
user = response;
} else {
user = response.data[0][key];
}
}, function errorCallback(err) {
console.log(err);
});
return user;
};
And here is the variable where the user detail should be returned to:
var username = getUser(row['user_id'], 'username');
Please, tell where the problem is.