I want to work with sqlite with cordova framework for the first time. As I've read on a tutorial I should use ngcordova like this:
var db = null;
app.controller('mainCtrl', function ($scope, $ionicSideMenuDelegate) {
$scope.toggleLeft = function () {
$ionicSideMenuDelegate.toggleLeft();
}
$scope.toggleRight = function () {
$ionicSideMenuDelegate.toggleRight();
}
})
.controller('home_ctrl', function ($scope, $cordovaSQLite) {
db = $cordovaSQLite.openDB({name: "my.db"});
//db = $window.opendb({name: "my.db"});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people(id integer primary key, firstname text, lastname text)")
})
;
When I run this code an error says:
TypeError: Cannot read property 'openDatabase' of undefined
In some articles like this: How do I use the ngCordova sqlite service and the Cordova-SQLitePlugin with Ionic Framework?
recommends to use commands like this: ionic start myApp sidemenu
I don't know what is it, I just use cordova command like: cordova run android
or cordova create my_project
What should I do to run my create a table from my cordova project?
You might take a look at this tutorial:
https://www.thepolyglotdeveloper.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/
When you see this error:
TypeError: Cannot read property 'openDatabase' of undefined
It is happening for one of a few reasons:
$cordovaSQLite
methods in the $ionicPlatform.ready()
function.The most common reasons for this error are #1 and #2. Native plugins, must be used only after the application is confirmed ready, thus the $ionicPlatform.ready()
method. Since native plugins use native code, you cannot test them from your web browser.
Read through the tutorial I linked because it should help you.
Regards,
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