I have a resolve promise function that uses $q service, where there is some generic code to resolve/reject based on certain conditions. I have a scenario wherein I would have to execute api2 only after api1 is successfully resolved. But both the calls are happening asynchronously. I have pasted the pseudo code below. Please help. Thanks a lot in advance.
var resolvePromise = function(promise)
{
    var defer = $q.defer();
    promise.then(function(response)
        if(certain conditions are true)
        {
             defer.reject(err)
        }
        defer.resolve();
    )
    .catch(function(errors){
        defer.reject(errors);
    })
   return defer.promise;
}
function synchronousCalls()
{
    var promise1 = service.getApi1();
    var promise2 = service.getApi2();
    return resolvePromise(promise1).then(function(){
          return resolvePromise(promise2);
    })
}
function getData()
{
    synchronousCalls().then(function(){
       console.log("synchronous run of apis ended");
    })
}
 
     
    