-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.

4
  • it is not resolved $resolved: false, so you can't iterate over it Commented Apr 8, 2015 at 11:50
  • Try to use it exactly as shown in the manual: docs.angularjs.org/api/ngResource/service/$resource Commented Apr 8, 2015 at 11:51
  • Kamil, then what approach i should follow? Commented Apr 8, 2015 at 11:52
  • 2
    @divakar There is a good example implementation in the answer to this StackOverflow question. stackoverflow.com/questions/13269882/… Commented Apr 8, 2015 at 11:54

1 Answer 1

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);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.