How do I use the ngCordova sqlite service and the Cordova-SQLitePlugin with Ionic Framework? How do I use the ngCordova sqlite service and the Cordova-SQLitePlugin with Ionic Framework? angularjs angularjs

How do I use the ngCordova sqlite service and the Cordova-SQLitePlugin with Ionic Framework?


If someone still got an error when trying to run it in a browser, try this one:

if (window.cordova) {      db = $cordovaSQLite.openDB({ name: "my.db" }); //device    }else{      db = window.openDatabase("my.db", '1', 'my', 1024 * 1024 * 100); // browser    }


So Turns out that it is because Cordova is platform specific and doesn't work when you run ionic serve

I was able to run the same code on an android device with out issue when I built and deployed.

Update

you can replace the cordova plugin with window to use the websql databasesso instead of sqlitePlugin.openDatabase() you can use window.openDatabase()


In Ionic 2, I am using the following code.

constructor(platform: Platform) {platform.ready().then(() => {  if(platform.is("cordova")){    //USE Device  }  else {    //USE Browser  }  StatusBar.styleDefault();});