How to load the .run before the controller
<p>I'm doing an app in Cordova using a pre-populated db, I'm trying to put the result of a db search in a &lt; select > but without using a ng-click in my html file (that is the only way I found so far to solve the problem) I tried with ng-init but it executes the function in my controller before the .run that is where I load my db, here is the code.</p>

<p>app.js</p>

<pre><code>var ionicApp = angular.module('starter', ['ionic', 'ngCordova']);
var db = null;

ionicApp.run(function($ionicPlatform, $cordovaSQLite) {
 $ionicPlatform.ready(function() {
  if(window.cordova &amp;&amp; window.cordova.plugins.Keyboard) {
   cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

   cordova.plugins.Keyboard.disableScroll(true);
  }
  if(window.StatusBar) {
    StatusBar.styleDefault();
  }
    window.plugins.sqlDB.copy("mydb.db","./plugins/me.rahul.plugins.sqlDB/WWW/sqlDB.js",function() { 
      db = $cordovaSQLite.openDB("mydb.db");
    }, function(error) {
       db = $cordovaSQLite.openDB("mydb.db");
    });
  });
});

ionicApp.controller('first-select', function($scope, $cordovaSQLite){
  $scope.options = [];
  $scope.select = function () {
    var query = "SELECT emp FROM adm_cia";
    $cordovaSQLite.execute(db, query,[]).then(function(res){
      if(res.rows.length &gt; 0){
        var newOptions = [];
        for(var i = 0; i &lt; res.rows.length; i++){
          var idn = (i+1).toString();
          newOptions.push({id: idn, name: res.rows.item(i).emp});
         }
      $scope.options = newOptions;
      } else {    }
    }, function(error){
  });
 }
})
</code></pre>

<p>and the index.html</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
   &lt;head&gt;
        &lt;meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"&gt;
        &lt;meta name="format-detection" content="telephone=no"&gt;
        &lt;meta name="msapplication-tap-highlight" content="no"&gt;
        &lt;meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"&gt;
        &lt;meta charset="utf-8"&gt;
        &lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"&gt;
        &lt;link href="lib/ionic/css/ionic.css" rel="stylesheet"&gt;
        &lt;link rel="stylesheet" href="lib/mobile-angular-ui/dist/css/mobile-angular-ui-base.min.css"/&gt;
        &lt;link href="css/style.css" rel="stylesheet"&gt;
        &lt;script type="text/javascript" src="js/jquery.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript" src="bootstrap/js/bootstrap.min.js"&gt;&lt;/script&gt;
        &lt;script src="js/angular-aside/docs/js/angular.min.js"&gt;&lt;/script&gt;
        &lt;script src="js/angular-route/angular-route.min.js"&gt;&lt;/script&gt;
        &lt;script src="lib/mobile-angular-ui/dist/js/mobile-angular-ui.min.js"&gt;&lt;/script&gt;
        &lt;script src="lib/ionic/js/ionic.bundle.js"&gt;&lt;/script&gt;
        &lt;script src="js/ng-cordova.min.js"&gt;&lt;/script&gt;
        &lt;script src="cordova.js"&gt;&lt;/script&gt;
        &lt;script src="js/app.js"&gt;&lt;/script&gt;
        &lt;title&gt;Login&lt;/title&gt;
    &lt;/head&gt;
    &lt;body ng-app="starter" ng-controller="first-select" class="scrollable-content" ng-init="select()"&gt;
        &lt;form id="login" method="get" action="indice.html"&gt;
            &lt;div align="justify"&gt;
                &lt;h1 class="color-letra"&gt;Nova Plus mobile&lt;/h1&gt;
                &lt;div class="form_input"&gt;
                    &lt;input ng-click="select()" type="text" placeHolder="Ususario" name="username" requiered&gt; &lt;!-- this ng-click will be instead of the ng-init and is the only way that it works--&gt;
                &lt;/div&gt;
                &lt;div class="form_input"&gt;
                    &lt;input type="password" placeHolder="Contraseña" name="password" required&gt;
                &lt;/div&gt;
                &lt;div class="form_input" style="margin-bottom : 30px"&gt;
                    &lt;select name="empresas" class="empresas" required&gt;
                        &lt;option value=""&gt;Seleccione empresa&lt;/option&gt;
                        &lt;option value="1"&gt;prueba&lt;/option&gt;
                        &lt;option ng-repeat="option in options" value="{{option.id}}"&gt;{{option.name}}&lt;/option&gt;
                    &lt;/select&gt;
                &lt;/div&gt;
                &lt;div class="centrar"&gt;
                    &lt;button type="submit" id="btn-default"&gt;Enviar&lt;/button&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/form&gt;
    &lt;/body&gt;
 &lt;/html&gt;
</code></pre>

<p>this code will do the select() function first and after it will open the database, the idea is that it first open the database and after do the select() function.</p>

<p>Regards.</p>