0

Hi in my controller I have following code that fetches data from db. It is fetching data correctly there is no problem as I can see it in firebug.

 $scope.up = supRepository.getPrice.query({ id: sup._id }, function(data) {
                $scope.up = data;
            });
            alert($scope.up.description);

Problem is that on alert it just gives me empty box nothing in it. No error or value. I believe this might be related to timing? Please let me know how can i fix it. So if it is timing issue it waits until the values are available. Thanks

1 Answer 1

1

You need to move the alert into the callback so you know you have already received data

supRepository.getPrice.query({ id: sup._id }, function(data) {
      $scope.up = data;
      alert($scope.up.description);
});
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.