MagicDragon MagicDragon - 22 days ago 10
AngularJS Question

Cordova SQLite with ionic native in angular 1

I'd like to add DeepLinking to my hybrid application which I found out works with ionic-native.

I have a working project with SQLite datebase tested on iOS and android but when I include

ionic.native
in my app module it throws an error.


app.module:
angular.module('myApp', ['ionic', 'ionic.native'])


app.run: openDB is at app.js:207

ionic.Platform.ready(function () {
db = $cordovaSQLite.openDB({name: 'my.db', location: 'default'});
});




Error: Uncaught TypeError: undefined is not a function. app.js:207


The blog post about ionic deep linking I try to put into practice

Ionic deep linking plugin docs for Ionic/Angular 1


I guess it's related to ionic-native's plugin list since it has SQLite also.

Answer

I could solve the problem by changing the way of opening the database. At the time when I was implementing the cordova SQLite database had problems on iOS with window.sqlitePlugin.openDatabase() but was not using ionic.native so back then using the $cordovaSQLite.openDB() solved my problem since it calls directly the plugin.

The way I open the db now:
ionic.Platform.ready(function () { db = window.sqlitePlugin.openDatabase({name: 'qpi.db', location: 'default'}); });

Comments