I am currently working on a mobile application built with Cordova and Ionic. The default page of the application requires the use of the SQLLite plugin.
https://github.com/brodysoft/Cordova-SQLitePlugin
The issue I am facing is that the view contains
ng-init="setData()"
This calls the controller method that works with the SQL Lite plugin. However, this method is triggered before the deviceready event is initialized (the plugin can only be initialized after the deviceready event).
I attempted to implement the following workaround:
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
db = window.sqlitePlugin.openDatabase({name:"callplanner"});
}
However, this solution did not work for me.
So I tried another approach:
.factory('cordova', function () {
return {
test: function(){
document.addEventListener("deviceready", this.ready, false);
},
ready: function(){
alert("Ready");
db = window.sqlitePlugin.openDatabase({name:"callplanner"});
}
}
})
And in the controller initialization, I attempted:
cordova.test();
Unfortunately, this approach also did not work (devicereadfy is fired after ng-init).
In my search for a solution, I came across this article:
However, I am unsure how to implement a "splash screen" before the app is ready and how to set a timeout.
Does anyone have any ideas on how to solve this problem?
Thank you in advance for any advice or assistance.