I am running into an issue where the client is not waiting for the server response. I have a big query that runs on server and returns data. But on client side, it is not waiting for the response from server before processing the data. I tried angularjs .then function without success. Service is "myService" as below.
this.getJsonData = function() {
var searchData = caller.get("/metadata/Search").then(function(result){
return result.data;
});
return searchData;
};
calling service
myService.getJsonData().then(
function(data) {
formatData(data);
},
function(err) {
console.log("Error here" + err);
});
Now formatData is called, while the response from server call in pending in getJsonData.
Can anyone please help me what could be done here to resolve the issue.
**********Edited********** Tried this but didn't work either
this.getJsonData = function() {
var deffered = $q.seDefer();
caller.get("/metadata/Search").then(function(result){
deffered.resolve(result.data);
});
return deffered.promises;
};