Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Code is not executed in the order

$
0
0

@Alexandre75 wrote:

Hi,

I have a strange comportement with my code in Ionic : the code is not executed in the order.

In one function in my controller, i put several alerts to undesterand a bug, and an alert in the end of my method. The last alert is set before the alert I put at the start of my method when i test it. There is the code :
$scope.add = function()
{

$scope.final_d = $scope.transac.dat; //Finale date with date and hours from the form
$scope.final_d.setHours($scope.transac.ho.getHours());
$scope.final_d.setMinutes($scope.transac.ho.getMinutes());
$scope.final_d =  $scope.final_d.getTime(); //Timestamp

//Update solde user
var query = "SELECT * FROM options WHERE name = 'solde'";
$cordovaSQLite.execute(db, query).then(function(res) {
    $scope.solde = parseFloat(res.rows.item(0).value);
    alert("Solde chargé : ");
    alert($scope.solde);

});

//Upadate sold people
query = "SELECT * FROM people WHERE id = ?";
$cordovaSQLite.execute(db, query, [$scope.choice.id]).then(function(res) {
    $scope.solde_people = res.rows.item(0).solde;
});



if ($scope.transac.type == 0) // User give money
{
    alert("Solde censé être chargé : ");

    alert($scope.solde);

    $scope.solde = $scope.solde + parseFloat($scope.transac.amount);

    alert("after addition with new value");
    alert($scope.solde);

    $scope.solde_people = $scope.solde_people + $scope.transac.amount;

}

The alert alert("Solde censé être chargé : "); is set before the alert alert("Solde chargé : ");

Therefore, my bug come from this comportement, because i use a var that depends from a precedent request who is made after i need it... Do you have any idea about this ?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>