0

I am trying to use ionic framework with Sqllite . Here is my app.js code

       var db = null;
angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])

.run(function($ionicPlatform,$cordovaSQLite) {
  $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);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
    db = $cordovaSQLite.openDB({ name: "my.db" });
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people(id interger primary key , firstname text, lastname text)");
  });
})

And my index.html code is here

<script src="lib/ionic/js/ionic.bundle.js"></script>

  <script src="js/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

when i run following commands

ionic serve

it opens http://localhost:8100/#/login

Now i have two questions

1) it is giving me error

TypeError: n.sqlitePlugin is undefined

2) Where my.db is created. Can i view it physically

Thanks

Hitu Bansal
  • 2,917
  • 10
  • 52
  • 87
  • 2
    related question, http://stackoverflow.com/questions/26101120/how-do-i-use-the-ngcordova-sqlite-service-and-the-cordova-sqliteplugin-with-ioni – shakib May 11 '15 at 04:48
  • 2
    when developing in browser, you can see the db in developer console, ex. when using `db = window.openDatabase("jobs", '1', 'my', 1024 * 1024 * 100);`, in chrome you can find the db `jobs` in developer console>Rosources>WebSql, after developing, when build in platform device you should use `db = $cordovaSQLite.openDB({ name: "jobs" });` – shakib May 11 '15 at 05:10
  • 1
    also viewing database from device, http://stackoverflow.com/questions/8321246/how-can-i-read-my-database-from-ddms – shakib May 11 '15 at 05:16
  • Thanks @shakib., i got my answer – Hitu Bansal May 11 '15 at 05:24
  • Please can you share your answer? – Richard Sep 30 '16 at 12:04

1 Answers1

0

You need to separete the code for the device and for the browser. This work for me, and other persons:

if (window.cordova) {
    //device
    db = $cordovaSQLite.openDB({ name: "my.db" });
}else{
    // browser
    db = window.openDatabase("my.db", '1', 'my', 1024 * 1024 * 100);
}
jcravelo
  • 1
  • 2