Uncaught ReferenceError: $cordovaSQLite is not defined

I’m new using Ionic and know a little about javascript.
I want to connect to an existing sqlite database and read some values.
I am using ngcordova because it provides a plugin for make it easier to access the sqlite plugin.

I started from a blank app. These are the plugins i added to the app (besides the included ones):
cordova-plugin-dbcopy
cordova-sqlite-ext

I am using genymotion to emulate a real device, so i can use ionic run android and don’t have plugin issues (i understand plugins won’t work with ionic serve or using a web browser)

I downloaded the latest ng-cordova.min.js to the project/www/js folder
on index.html i put before the cordova.js line and after the lib/ionic/js/ionic.bundle.js line.

I registered the module dependency in the app.js file:
angular.module(‘starter’, [‘ionic’, ‘ngCordova’])

Inside $ionicplatform.ready() i am trying to do the following:

window.plugins.sqlDB.copy(“sqlite.db”, 0, function() {
db = $cordovaSQLite.openDB({name: ‘sqlite.db’, location: ‘default’});
console.log("database read);
}, function(error) {
console.error("Error copying db: " + error);
db = $cordovaSQLite.openDB({name: ‘sqlite.db’, location: ‘default’});
});

However, when doing ionic run android, the app appears in my genymotion emulator, and using chrome browser to debug it i get the error:

Error in Success callbackId: sqlDB951999623 : ReferenceError: $cordovaSQLite is not defined
cordova.js:314 Uncaught ReferenceError: $cordovaSQLite is not defined
ionic.bundle.js:26794 TypeError: Cannot read property ‘transaction’ of null
at Object.execute (file:///android_asset/www/js/ng-cordova.min.js:9:23736)
at Scope.$scope.selectAll (file:///android_asset/www/js/app.js:40:24)

What am i doing wrong?

1 Like