Redirect inside function requires 2 button clicks, why?


I am having an issue with redirecting to a different page from within a function, that is called on a button press.

The function runs as it should no problem, but the redirect does not work on first click, you have to click the button a second time for the redirect?

The redirect is: Apperyio.navigateTo('Pay');

Any idea why I have to click the button twice?

Here is the function, which is called on the button press event!

Note: I am using the web interface and NOT on a mobile device!

var service = new google.maps.DistanceMatrixService();

var origin = {lat: origLat, lng: origLong};
var destination = dest;
origins: [origin],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false,
unitSystem: google.maps.UnitSystem.IMPERIAL

function callback(response, status) {

var orig = document.getElementsByClassName("orig"),
dest = document.getElementsByClassName("dest"),
dist = document.getElementsByClassName("dist");

if(status=="OK") {

orig.value = response.originAddresses[0];
dest.value = response.destinationAddresses[0];
dist.value = response.rows[0].elements[0].distance.text;

mileCostAmt = parseFloat(dist.value) * 3.14;
totalCost = parseFloat(mileCostAmt) + 75;
totalCost = totalCost.toFixed(2);
$scope.PayDetails.amount = totalCost;

Apperyio.navigateTo('Pay'); // Issue with this redirect

} else {
alert("Sorry, we couldn't find that destination, please try again!");
1 person has
this question