Reputation: 981
I have written the following in my controller
$scope.$on('$ionicView.afterEnter', function(event, data){
var db = null;
db = $cordovaSQLite.openDB({ name: 'app.db' });
$cordovaSQLite.execute(db,"CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
});
and I have also installed sqlite plugin in my project.
but whenever i am running my controller i am gettin an error $cordovaSQLite is not defined
Upvotes: 0
Views: 473
Reputation: 1635
In .run function you should initialize db like as:
if (window.cordova) {
// App syntax
self.db = window.sqlitePlugin.openDatabase(CONFIG.DB_NAME);
} else if (window.openDatabase) {
self.db = window.openDatabase(CONFIG.DB_NAME, '1.0', 'database', -1);
}
Upvotes: 0
Reputation: 364
Install sqlite plugin using the following command,
cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git
Then in app.js page, declare $cordovaSQLite in run function & ADD your db code,
.run(function($ionicPlatform,$cordovaSQLite,$timeout,$ionicLoading, $cordovaDialogs){
var db = null;
db = $cordovaSQLite.openDB({ name: 'app.db',location:1});
$cordovaSQLite.execute(db,"CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
})
Hope this will Helps!!!!
Upvotes: 0
Reputation: 647
To verify that both the Javascript and native part of sqlite plugin are installed in your application:
window.sqlitePlugin.echoTest(successCallback, errorCallback);
Listen for onDeviceReady event and then use sqlite.
document.addEventListener("deviceready", yourCallbackFunction, false);
function yourCallbackFunction()
{
// Sqlite API implementation here
}
Upvotes: 1