Mikyas TADESSE Mikyas TADESSE - 5 days ago 5
AngularJS Question

How to access data in a promise angularjs

I wanted to access a data in promise. I have the following code :

function getUser() {
Users.query({username: usersOnline}).$promise.then(function (results) {
console.log(results);
$scope.userss = results;
return results;
}, function(error) {
// console.log(error);
//$scope.meetups = [];
});
//$scope.userss[0].username='oui';
}
$scope.lol=getUser();
$scope.lol.then(function(user){
console.log(user.username);
});


But i get an error saying cant find property then of undefined can you help

Answer

Return Users.query promise from getUser user function, as caller function is performing .then(expecting promise) there.

function getUser() {
//return promise here
    return Users.query({username: usersOnline}).$promise
    //other code as is

}
Comments