title: How to Deviceready in right way in Ionic application?
body: <p>I have Cordova and Ionic based mobile application. On the default page which is loaded after the start of the application is need to work with SQLLite plugin. </p>
  
  <p><a href="https://github.com/brodysoft/Cordova-SQLitePlugin">https://github.com/brodysoft/Cordova-SQLitePlugin</a></p>
  
  <p>Problem is that view contains </p>
  
  <pre><code>ng-init="setData()"
  </code></pre>
  
  <p>Which is calling the controller method where is worked with SQL Lite plugin. And because of the the method is called before the deviceready event is not initialized (plugin can be initialized only after deviceready event).</p>
  
  <p>So I tried this workaround:  </p>
  
  <pre><code>.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 &amp;&amp; window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        db = window.sqlitePlugin.openDatabase({name:"callplanner"});
      }
  </code></pre>
  
  <p>But this not working for me.</p>
  
  <p>So i tried second solution:</p>
  
  <pre><code>.factory('cordova', function () {
    return {
        test: function(){
            document.addEventListener("deviceready", this.ready, false);
        },
        ready: function(){
              alert("Ready");
              db = window.sqlitePlugin.openDatabase({name:"callplanner"});
        }
  
    }
  })
  </code></pre>
  
  <p>and in controller init i tried:</p>
  
  <pre><code>cordova.test();
  </code></pre>
  
  <p>But this is not working to (devicereadfy is fired after ng-init).</p>
  
  <p>After that i found this article:</p>
  
  <p><a href="http://java.dzone.com/articles/ionic-and-cordovas-deviceready">http://java.dzone.com/articles/ionic-and-cordovas-deviceready</a></p>
  
  <p>But i did not understand how to put "splash screen" before app is ready and how to set timeout.</p>
  
  <p>Have somebody idea how can I solve this problem?</p>
  
  <p>Many Thanks for any advice or help.</p>