I have a problem converting the promise returned by the service to the controller. What I want is to create an array of JSON objects from the data contained in promise. Here is what I receive in the controller:
Here is the line that is used for printing that data:
console.log("controller unmatched: ", unmatched.getData(sFilter));
Here "unmatched" is the service, and getData() is its function.
Thanks!
json() The json() method of the Response interface takes a Response stream and reads it to completion. It returns a promise which resolves with the result of parsing the body text as JSON .
The value is returned because promise has been resolved passing the value in response.
A Promise represents a value that will be available some time in the future, or never. This means its eventual value can't be returned by your unmatched.getData()
function.
What you need to do is to make unmatched.getData()
return the actual promise and then you take action when that promise resolves:
unmatched.getData(sFilter).then(function(result) {
console.log("controller unmatched: ", result);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With