You can’t do that, JavaScript does not provide any blocking API (aka wait handle or mutex), once you decide (or are forced) to use a promise they become pervasive in your code like a virus :-) The only think you can do is to return the promise from the test function and let the caller decide how to move on.
.m From: [email protected] [mailto:[email protected]] On Behalf Of Jideobi Ofomah Sent: sabato 22 febbraio 2014 21:23 To: [email protected] Subject: [AngularJS] how to assign promise return data to calling function variable i want to do the following function test(){ var user = null; userFactory.get(userId).then(function(data){ user = data; console.log(user); }); return user; } this returns null while console.log print user object, how to i return user object gotten from get() promise -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To post to this group, send email to [email protected]<mailto:[email protected]>. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
