someone help me please, i dont know where is the problem with my code , i got an error message from transaction function ( i know that from the alert that i defined inside it)
app.js
// global variable where will define the database
var db = null;
angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
/* DATABASE INTEGRATION */
if (window.sqlitePlugin) {
// copy the database
window.plugins.sqlDB.copy("utilisateurs.db",
function () {
// copy success, if not yet been copied
// set "db" as the database
db = window.sqlitePlugin.openDatabase({name: "utilisateurs.db"});
alert("copysuccess");
}, function() {
// copy error, if it has already been copied
// set "db" as the database
db = window.sqlitePlugin.openDatabase({name: "utilisateurs.db"});
alert("copyerror");
});
} else {
db = window.openDatabase("utilisateurs.db", "1.0", "utilisateurs.db", 200000);
alert("copy browser");
}
});
})
.controller('ExampleCtrl', function($scope) {
$scope.order = function(){
// db is your database defined before
console.log("start order ");
db.transaction(function(tx) {
// running a sql querie
tx.executeSql("SELECT username, password FROM users", [], function(tx, res) {
var len = res.rows.length;
for (var i = 0; i < len; i++) { // loop as many times as there are row results
alert( res.rows.item(i).username +' '+ res.rows.item(i).password ); // showing the results
}
}, function(e) {
console.log("error trans " + e);
alert("ERROR: " + e.message);
});
});
};
})
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content ng-controller="ExampleCtrl">
<button class="button" ng-click="order()"></button>
</ion-content>
</ion-pane>
</body>
</html>