I'm trying to execute some queries on a sqlite database but its not working if I do it in a angularjs controller.
My controller looks like this:
.controller('BrowseCtrl', function($scope,$cordovaSQLite,$timeout,ProductService){
var dbName = 'spareParts.db';
var db = $cordovaSQLite.openDB(dbName);
var query = "SELECT c.name as name, c.id as id FROM cars as c";
db.transaction(function(tx) {
tx.executeSql(query, [], function(tx, res) {
if(res.rows.length > 0) {
for(var i = 0; i<res.rows.length; i++) {
var entry = res.rows.item(i);
console.log("Entry ID: "+entry.id);
}
} else {
console.log("No results found");
}
}, function(e) {
console.log("ERROR: " + e.message);
});
});
})
If I use the same code in the .run function of the app.js everything works great. Like here:
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
...
var dbName = 'spareParts.db';
db = $cordovaSQLite.openDB(dbName);
var query = "SELECT c.name as name, c.id as id FROM cars as c";
db.transaction(function(tx) {
...
So what did I miss? I also imported the ng-cordova.min.js above the cordova.js explained here: http://ift.tt/1zsfJve
Thanks for any help.
Aucun commentaire:
Enregistrer un commentaire