0

Now I need to access some value which from promise.but it return undefined. Do I have to do it inside promise.then(function(){})? Here is my code:

var promise = PCservice.loadPersonalCCList();

promise.then(function(data){
  $scope.personalccinfor = data.CCMSGSRSV1.PERSONALCARDLISTRS.PERSONALCCLISTINFO.PERSONALCCLIST;
  $scope.cardinfo = data.SIGNONMSGSRSV1.SONRS.PROFILE;  

  console.log($scope.cardinfo.COMPANYCODE);         
});

console.log($scope.cardinfo.COMPANYCODE);

As you can see, I can access the code inside, but I need to make another ajax call which needs this data.The first console gives me what I want, but the second gives me undefined

Mikko Viitala
  • 8,066
  • 4
  • 37
  • 57
linyuanxie
  • 767
  • 4
  • 13
  • 28
  • Second .log is executed first, before promise is resolved so in that point it is still undefined. – Mikko Viitala Feb 25 '15 at 19:51
  • yah, if I keep the console.log which inside promise, it can print out the data,but when I move it out( which I need to access data),it print undefined. – linyuanxie Feb 25 '15 at 19:55

0 Answers0