I've been struggling for hours trying to figure out how $q works. I'm attempting to use it with a function from the google.maps API, but I just can't seem to grasp it on my own. Maybe I completely misunderstand $q. Can someone help me or provide some insight?
Here's a simple example of what I'm trying to accomplish:
var geocoder = new google.maps.Geocoder();
let promise1 = geocoder.geocode({address: "someAddress"});
let promise2 = geocoder.geocode({address: "someOtherAddress"});
$q.all([promise1, promise2]).then(data => {
console.log(data)
});
//The output I'm getting is: [undefined, undefined], which is not what I expected.
Where am I making mistakes? Here's the original async method from the Google API that works fine.
var geocoder = new google.maps.Geocoder();
geocoder.geocode({address: "someAddress"}, function(response, status){
if(status === 'ok')
//Do what I need with the response
else
//Do something else
});
I want to work with multiple requests, not just one. So, I need to store all the responses (and wait for them as it's an async function) before proceeding. That's why I'm trying to use $q to achieve my goal.
PS: I know there are many discussions about $q, but even after hours of researching, I can't seem to find a solution. Please don't suggest googling it.
Thanks in advance for your help!