The
getData
function returns a
Promise - something which will produce a result at some point in the future.
Promises[
^]
JavaScript Promises ... In Wicked Detail - Matt Greer[
^]
The function you pass to
then
will not be executed until the result has been produced. That will be at some point
after your
returnData
function has returned.
You can't return the result of an asynchronous operation before that operation has completed. You'll need to change your function to return the promise instead, and then move the code that uses the result of the function into a callback:
function returnData(){
return _myService.getData();
};
...
returnData().then(function(data){
});