1

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

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299

1 Answers1

2

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

}
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299