Thursday, 15 May 2014

javascript - Issue with nested asynchronous function not returning data in time -


I rely on a component, i.e. the which returns a value function for it it occurs.

Unfortunately, I'm not sure how to return something back from the time of the nested asynchronous function ( addressAutocomplete () ):

  $ Scope.chooseAddress = function (input) {var results = []; If (Input) {geolocationService.addressAutocomplete (Input, Function (Data) {Results = Data. Delegation; // Asynchronous and will be removed very late ...}); } Return Results; // I have to return something to my function ...};  

As long as the addressAutocomplete function is complete, the result var has already been returned and it is definitely an empty array ... < / P>

Can anyone please help?

You need to expose the fact that the call to select the asynchronous of the callees Select you can get it by returning it.

Update

  $ scope.chooseAddress = function (input) {var deferred = $ q.defer (); If (input) {geolocationService.addressAutocomplete (input, function (data) {deferred.resolve (data.predictions);}); } And (deferred.resolve ([]);} Refunded Advertise;};  

Then you type selectAddress such as

  

No comments:

Post a Comment