I have 1 issue in ngCordova plugin cordovaSQLite. Below code:
var db = $cordovaSQLite.openDB({ name: "myDB.db" });
I'm using ionic serve
in browser.
Error:
Uncaught TypeError: Cannot read property 'openDatabase' of undefinedng-cordova.js:5058
openDBapp.js:27
(anonymous function)ionic.bundle.js:37388
(anonymous function)ionic.bundle.js:2241
onPlatformReadyionic.bundle.js:2220
onWindowLoad
Could you please help me?
As stated by user jonnie in his answer
Cordova is platform specific and doesn't work when you run ionic serve
and
you can replace the cordova plugin with window to use the websql databases so instead of sqlitePlugin.openDatabase() you can use window.openDatabase()
It should work on actual devices just fine.
You are getting this error because you are trying to get database connection from android but using wrong function openDatabase(). This function will use in case of client (browser). Use openDb() function to get database connection from android.
if (window.cordova) {
db = $cordovaSQLite.openDB({ name: "my.db" }); //device
console.log("Android");
}
else{
db = window.openDatabase("my.db", '1', 'my', 1024 * 1024 * 100); // browser
console.log("browser");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With