mercredi 26 août 2015

Cannot access cordova's SQL-lite storage plugin

I am building a simple app using Cordova and AnglerJS, for the database works I decided to use the cordova-sqlite-storage. Using Cordova's CLI command cordova plugin add http://ift.tt/1hfTp15 I was able to install the plugin. But when I try to use it I get this error:

Uncaught TypeError: Cannot read property 'openDatabase' of undefined application.js:6

Here is the code:

document.addEventListener('deviceready', function(){
    angular.bootstrap(document.querySelector('body'), ['App']);
});

var application = angular.module('App', ['ngRoute']);

application.controller('controller', function($scope){
    var db = window.sqlitePlugin.openDatabase({name: "database.db", location: 2});
});

I know that using any Cordova plugin should be called inside the "deviceready" event callback, but as you can see Angular.Bootstrap holds everything until the device is ready. I even tried wrapping the controller in the "deviceready" listener but it didn't work too.

I am suspecting that the plugin itself/installation wasn't correct, are there any farther steps than using the cordova plugin add ... ?!

Aucun commentaire:

Enregistrer un commentaire