-1

Hi i have been trying to use foreach on the returned response which not seems to be working. Can anybody tell me what am doing wrong, I have also tried with promises but not seems to be working.

$scope.signuser=Login.query({email:$scope.user.signemail});

Response in console:

  [$promise: d, $resolved: false]
  0: e
  $promise: d$$state: Objectpending: undefinedprocessScheduled: falsestatus:                               value: Array[1]

I have tried using $scope.signuser[0] which seems to be not working as well as foreach.Also tried with $Promises. What am doing wrong? I need to access the 0th element of the variable. Any help would be appreciated Thanks in advance.

divakar
  • 1,379
  • 6
  • 15
  • 31
  • it is not resolved `$resolved: false`, so you can't iterate over it – Kamil Apr 08 '15 at 11:50
  • Try to use it exactly as shown in the manual: https://docs.angularjs.org/api/ngResource/service/$resource – deceze Apr 08 '15 at 11:51
  • Kamil, then what approach i should follow? – divakar Apr 08 '15 at 11:52
  • 2
    @divakar There is a good example implementation in the answer to this StackOverflow question. http://stackoverflow.com/questions/13269882/angularjs-resource-restful-example – Jon Koops Apr 08 '15 at 11:54

1 Answers1

2

It looks like you are doing this all in your controller, so try this following pattern for now. You should be able to see what is going on here, basically we're placing a $watch on $scope.signuser which will keep track of it's value so we can log it out after our promise has resolved.

$scope.signuser = null // for now - until promise is resolved

Login.query({ email: $scope.user.signemail }).then(function(response) {
    $scope.signuser = response.data[0];
});

$scope.$watch('signuser', function(newValue, oldValue) {
    console.log(newValue);
});
scniro
  • 16,844
  • 8
  • 62
  • 106