Search code examples
angularjscordovaionic-frameworkcordova-plugins

Ionic Cordova SQLite plugin error Cannot read property 'openDatabase' of undefined


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

enter image description here

Could you please help me?


Solution

  • 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.