2016-04-03 13 views
1

I SQLite cordova installiert haben Plugin diese Anweisung verwenden, wie folgend: http://ngcordova.com/docs/plugins/sqlite/

Bitte schauen Sie auf Controller-Code folgende:

.controller('PlaylistsCtrl', function ($scope, $cordovaSQLite) { 
    $scope.playlists = [ 
     { title: 'Reggae', id: 1 }, 
     { title: 'Chill', id: 2 }, 
     { title: 'Dubstep', id: 3 }, 
     { title: 'Indie', id: 4 }, 
     { title: 'Rap', id: 5 }, 
     { title: 'Cowbell', id: 6 } 
    ]; 

    //var db = $cordovaSQLite.openDB({ name: "my.db" }); 

    //// for opening a background db: 
    //var db = $cordovaSQLite.openDB({ name: "my.db", bgType: 1 }); 

    //$scope.execute = function() { 
    // var query = "INSERT INTO test_table (data, data_num) VALUES (?,?)"; 
    // $cordovaSQLite.execute(db, query, ["test", 100]).then(function (res) { 
    //  console.log("insertId: " + res.insertId); 
    // }, function (err) { 
    //  console.error(err); 
    // }); 
    //}; 

}) 

Fehler:

enter image description here

+1

Haben Sie ngCordova injiziert? z.B. 'angular.module ('starter.controllers', ['ngCordova'])' – Huey

+0

Danke. Das war das Problem! Ich habe verwiesen https://www.thepolyglotdeveloper.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/ –

Antwort

3

Ich habe den Fehler durch Verweis auf diesen Link gelöst: https://www.thepolyglotdeveloper.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/

Schritt-1: Laden Sie dieses herunter: Link und kopieren Sie ng-cordova.min.js in Ihr "www/js" -Verzeichnis.

Schritt-2: Für diesen Befehl cmd verwenden

cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin.git 

Schritt-3: Ihre Datei index.html öffnen, und fügen Sie die folgende Zeile:

<script src="js/ng-cordova.min.js"></script> 

Es ist sehr wichtig, dass Sie hinzufügen es über der cordova.js Linie sonst wird es nicht funktionieren.

Schritt-4: Bevor wir ngCordova verwenden können, muss noch etwas hinzugefügt werden. Wir brauchen sie in unsere angular.module zu injizieren, in app.js gefunden, wie die folgenden:

angular.module('starter', ['ionic', 'ngCordova']) 

Das ist es. Jetzt ist SQLite verwendbar.