lundi 29 février 2016

sqlite cordova javascript crashes

So I have a sqlite database which opens and executes well, however when I make sqlite functions at startup, the app freezes.

  var init = (function() {
$scope.getAll();
})();

The problem is var init = function()

$scope.Route = [];
$scope.getAll = function() {
db = $cordovaSQLite.openDB("transportation.db");
    var query = "SELECT agency_id, agency_phone FROM agency";
    $cordovaSQLite.execute(db, query, []).then(function(res) {
        if(res.rows.length > 0) {
            for(var i = 0; i < res.rows.length; i++) {
                $scope.logerror = "Worked" + res.rows.item(i).agency_phone;
                $scope.Route.push({id: res.rows.item(i).agency_id, agency_phone: res.rows.item(i).agency_phone})
                $scope.stops = res.rows.item(i).agency_phone;
                console.log("SELECTED -> " + res.rows.item(i).agency_phone);
            }
        } else {
            $scope.logerror = "No results found";
            console.log("No results found");
        }
    }, function (err) {
        $scope.logerror = "ERROR";
        console.error(err);
    });

};

How can I solve this problem?

Aucun commentaire:

Enregistrer un commentaire